#include <bits/stdc++.h>
const long long int M = 1e9 + 7;
using namespace std;
vector<int> eg[200005];
int a, b, bw, cw, c, vis[200005], from[200005];
void dfs(int n, int w) {
  vis[n] = 1;
  if (w > bw) b = n, bw = w;
  for (auto it : eg[n])
    if (vis[it] == -1) from[it] = n, dfs(it, w + 1);
}
void dfsC(int n, int w) {
  if (~vis[n]) return;
  vis[n] = 1;
  if (w > cw) c = n, cw = w;
  for (auto it : eg[n]) dfsC(it, w + 1);
}
int main() {
  int n, u, v, i;
  while (~scanf("%d", &n)) {
    for (i = 1; i < n; i++)
      scanf("%d %d", &u, &v), eg[u].push_back(v), eg[v].push_back(u);
    memset(vis, -1, sizeof vis);
    a = b = bw = c = 0;
    for (i = 1; i <= n; i++)
      if (eg[i].size() == 1) {
        a = i, from[i] = -1, dfs(i, 0);
        break;
      }
    memset(vis, -1, sizeof vis);
    a = b, b = bw = c = 0;
    from[a] = -1, dfs(a, 0);
    memset(vis, -1, sizeof vis);
    int x = b;
    vis[a] = vis[b] = 1;
    while (from[x] != -1) {
      vis[x] = 1;
      x = from[x];
    }
    x = b, cw = 0;
    while (from[x] != -1) {
      for (auto it : eg[x])
        if (vis[it] == -1) dfsC(it, 1);
      x = from[x];
    }
    if (!c) c++;
    if (c == a || c == b) c++;
    if (c == a || c == b) c++;
    printf("%d\n%d %d %d\n", bw + cw, a, b, c);
  }
  return 0;
}
