#include <bits/stdc++.h>
using namespace std;
vector<int> g[200005], gx[200005];
int depth[200005];
int vis[200005];
int z[200005];
int flag = 0;
void dfs(int x, int fa) {
  depth[x] = depth[fa] + 1;
  vis[x] = 1;
  for (int i = 0; i < g[x].size(); i++) {
    int t = g[x][i];
    if (vis[t]) continue;
    dfs(t, x);
  }
}
void dfsx(int x, int end) {
  if (x == end) {
    flag = 1;
    z[x] = 1;
    return;
  }
  vis[x] = 1;
  for (int i = 0; i < g[x].size(); i++) {
    int t = g[x][i];
    if (vis[t]) continue;
    dfsx(t, end);
    if (flag) {
      z[x] = 1;
      break;
    }
  }
}
void dfsz(int x, int fa) {
  depth[x] = depth[fa] + 1;
  vis[x] = 1;
  for (int i = 0; i < gx[x].size(); i++) {
    int t = gx[x][i];
    if (vis[t]) continue;
    dfsz(t, x);
  }
}
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0);
  int maxn = 0;
  int index;
  for (int i = 1; i <= n; i++) {
    if (maxn < depth[i]) {
      maxn = depth[i];
      index = i;
    }
  }
  memset(depth, 0, sizeof(depth));
  memset(vis, 0, sizeof(vis));
  dfs(index, 0);
  int ans1 = index;
  maxn = 0;
  int index2 = 0;
  for (int i = 1; i <= n; i++) {
    if (maxn < depth[i]) {
      maxn = depth[i];
      index2 = i;
    }
  }
  int ans2 = index2;
  ans += depth[index2] - 1;
  memset(vis, 0, sizeof(vis));
  dfsx(ans1, ans2);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      if (z[i] == 1) {
        if (!z[g[i][j]]) gx[0].push_back(g[i][j]);
      } else {
        if (z[g[i][j]])
          gx[i].push_back(0);
        else
          gx[i].push_back(g[i][j]);
      }
    }
  }
  memset(depth, 0, sizeof(depth));
  memset(vis, 0, sizeof(vis));
  dfsz(0, 0);
  maxn = 0;
  int index3 = -1;
  for (int i = 1; i <= n; i++) {
    if (maxn < depth[i]) {
      maxn = depth[i];
      index3 = i;
    }
  }
  int ans3;
  if (index3 == -1) {
    for (int i = 1; i <= n; i++) {
      if (i != ans1 && i != ans2) {
        ans3 = i;
        break;
      }
    }
  } else {
    ans3 = index3;
    ans += depth[index3] - 1;
  }
  cout << ans << '\n';
  cout << ans1 << ' ' << ans2 << ' ' << ans3 << '\n';
  return 0;
}
