#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> bian[200010];
int vis[200010];
int dis1[200010];
void bfs1(int x) {
  memset(vis, 0, sizeof(vis));
  vis[1] = 1;
  dis1[1] = 0;
  queue<int> q;
  q.push(1);
  int te;
  while (!q.empty()) {
    te = q.front();
    q.pop();
    for (int i = 0; i < bian[te].size(); i++) {
      if (vis[bian[te][i]] == 0) {
        vis[bian[te][i]] = 1;
        dis1[bian[te][i]] = dis1[te] + 1;
        q.push(bian[te][i]);
      }
    }
  }
}
int dis2[200010];
void bfs2(int x) {
  memset(vis, 0, sizeof(vis));
  vis[x] = 1;
  dis2[x] = 0;
  queue<int> q;
  q.push(x);
  int te;
  while (!q.empty()) {
    te = q.front();
    q.pop();
    for (int i = 0; i < bian[te].size(); i++) {
      if (vis[bian[te][i]] == 0) {
        vis[bian[te][i]] = 1;
        dis2[bian[te][i]] = dis2[te] + 1;
        q.push(bian[te][i]);
      }
    }
  }
}
int dis3[200010];
void bfs3(int x) {
  memset(vis, 0, sizeof(vis));
  vis[x] = 1;
  dis3[x] = 0;
  queue<int> q;
  q.push(x);
  int te;
  while (!q.empty()) {
    te = q.front();
    q.pop();
    for (int i = 0; i < bian[te].size(); i++) {
      if (vis[bian[te][i]] == 0) {
        vis[bian[te][i]] = 1;
        dis3[bian[te][i]] = dis3[te] + 1;
        q.push(bian[te][i]);
      }
    }
  }
}
int a, b, c;
int te = 0;
int main() {
  scanf("%d", &n);
  int l, r;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &l, &r);
    bian[l].push_back(r);
    bian[r].push_back(l);
  }
  bfs1(1);
  te = 0;
  for (int i = 2; i <= n; i++) {
    if (dis1[i] > te) {
      te = dis1[i];
      a = i;
    }
  }
  bfs2(a);
  te = 0;
  for (int i = 1; i <= n; i++) {
    if (dis2[i] > te && i != a) {
      te = dis2[i];
      b = i;
    }
  }
  bfs3(b);
  te = 0;
  for (int i = 1; i <= n; i++) {
    if (dis2[i] + dis3[i] > te && i != a && i != b) {
      te = dis2[i] + dis3[i];
      c = i;
    }
  }
  printf("%d\n", (dis2[b] + dis2[c] + dis3[c]) / 2);
  printf("%d %d %d", a, b, c);
}
