#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> road[maxn];
int dst[maxn][3];
void dfs(int now, int before, int sum, int cas) {
  for (int i = 0; i < road[now].size(); i++) {
    if (road[now][i] != before) {
      dst[road[now][i]][cas] = sum + 1;
      dfs(road[now][i], now, sum + 1, cas);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  memset(dst, 0x7f, sizeof(dst));
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    road[x].push_back(y);
    road[y].push_back(x);
  }
  dst[1][0] = 0;
  dfs(1, 1, 0, 0);
  int a, b, c, Max = -0x7f7f7f7f;
  for (int i = 2; i <= n; i++)
    if (dst[i][0] > Max) {
      Max = dst[i][0];
      a = i;
    }
  dst[a][1] = 0;
  dfs(a, a, 0, 1);
  Max = -0x7f7f7f7f;
  for (int i = 1; i <= n; i++) {
    if (dst[i][1] > Max) {
      Max = dst[i][1];
      b = i;
    }
  }
  dst[b][2] = 0;
  dfs(b, b, 0, 2);
  int ans = -0x7f7f7f7f;
  for (int i = 1; i <= n; i++) {
    int x = dst[i][1] + dst[i][2];
    if (x > ans && i != a && i != b) {
      ans = x;
      c = i;
    }
  }
  ans = (ans + Max) / 2;
  cout << ans << endl;
  if (a > b) swap(a, b);
  if (b > c) swap(b, c);
  if (a > b) swap(a, b);
  cout << a << ' ' << b << ' ' << c << endl;
}
