#include <bits/stdc++.h>
using namespace std;
vector<int> p;
vector<vector<int> > ga;
pair<int, int> dfs(int v, int par = -1, int dist = 0) {
  p[v] = par;
  pair<int, int> res = make_pair(dist, v);
  for (int nxt : ga[v])
    if (nxt != par) res = max(res, dfs(nxt, v, dist + 1));
  return res;
}
int main() {
  int n;
  cin >> n;
  p = vector<int>(n);
  ga = vector<vector<int> >(n);
  for (int i = 1; i < n; i++) {
    int first, second;
    cin >> first >> second;
    ga[first - 1].push_back(second - 1);
    ga[second - 1].push_back(first - 1);
  }
  pair<int, int> da = dfs(0);
  pair<int, int> db = dfs(da.second);
  vector<int> diam;
  int v = db.second;
  while (v != da.second) {
    diam.push_back(v);
    v = p[v];
  }
  diam.push_back(da.second);
  if ((diam.size()) == n)
    cout << n - 1 << " " << endl
         << diam[0] + 1 << " " << diam[1] + 1 << " " << diam.back() + 1 << endl;
  else {
    queue<int> q;
    vector<int> d(n, -1);
    for (int v : diam) {
      d[v] = 0;
      q.push(v);
    }
    while (q.size()) {
      int v = q.front();
      q.pop();
      for (int to : ga[v]) {
        if (d[to] == -1) {
          d[to] = d[v] + 1;
          q.push(to);
        }
      }
    }
    pair<int, int> mx = make_pair(d[0], 0);
    for (int v = 1; v < n; v++) mx = max(mx, make_pair(d[v], v));
    cout << (diam.size()) - 1 + mx.first << endl
         << diam[0] + 1 << " " << mx.second + 1 << " " << diam.back() + 1
         << endl;
  }
  return 0;
}
