#include <bits/stdc++.h>
using namespace std;
int mark[200009];
int par[200009], dis[200009];
vector<long long int> g[200009];
int ans;
int bfs(int root) {
  par[root] = root;
  mark[root] = 1;
  queue<int> q;
  int last;
  q.push(root);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    last = cur;
    for (int i = 0; i < (int)g[cur].size(); ++i) {
      if (mark[g[cur][i]] == 0) {
        mark[g[cur][i]] = 1;
        par[g[cur][i]] = cur;
        q.push(g[cur][i]);
      }
    }
  }
  return last;
}
int myfun(int root, int last) {
  int ret;
  queue<int> q;
  q.push(root);
  dis[root] = 0;
  mark[root] = 1;
  while (par[last] != last) {
    q.push(last);
    dis[last] = 0;
    mark[last] = 1;
    last = par[last];
    ans++;
  }
  memset(par, 0, sizeof(par));
  while (!q.empty()) {
    int cur = q.front();
    ret = cur;
    q.pop();
    for (int i = 0; i < (int)g[cur].size(); ++i) {
      if (mark[g[cur][i]] == 0) {
        q.push(g[cur][i]);
        mark[g[cur][i]] = 1;
        dis[g[cur][i]] = dis[cur] + 1;
      }
    }
  }
  return ret;
}
void solve() {
  long long int n, i, root, j, last;
  cin >> n;
  memset(mark, 0, sizeof(mark));
  memset(par, 0, sizeof(par));
  memset(dis, 0, sizeof(dis));
  for (i = 0; i < n; ++i) {
    long long int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  root = bfs(1);
  memset(mark, 0, sizeof(mark));
  memset(par, 0, sizeof(par));
  last = bfs(root);
  memset(mark, 0, sizeof(mark));
  ans = 0;
  int mid = myfun(root, last);
  ans = ans + dis[mid];
  cout << ans << endl;
  cout << root << " " << mid << " " << last << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
