#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long int expo(long long int a, long long int b) {
  long long int r = 1;
  a = a % 1000000007;
  while (b) {
    if (b % 2) r = (r * a) % 1000000007;
    a = (a * a) % 1000000007;
    b = b / 2;
  }
  return r;
}
vector<int> adj[200001];
vector<int> dp1(200001);
vector<int> ind1(200001);
vector<int> ind2(200001);
vector<int> ind3(200001);
vector<int> dp2(200001);
vector<int> dp3(200001);
vector<int> up(200001);
vector<int> u_ind(200001);
void dfs(int i, int par) {
  int mx1 = 0, mx2 = 0, mx3 = 0;
  ind1[i] = ind2[i] = ind3[i] = i;
  for (auto x : adj[i]) {
    if (x == par) continue;
    dfs(x, i);
    if (mx1 < (1 + dp1[x])) {
      mx3 = mx2;
      ind3[i] = ind2[i];
      mx2 = mx1;
      ind2[i] = ind1[i];
      mx1 = 1 + dp1[x];
      ind1[i] = ind1[x];
    } else if (mx2 < (1 + dp1[x])) {
      mx3 = mx2;
      ind3[i] = ind2[i];
      mx2 = 1 + dp1[x];
      ind2[i] = ind1[x];
    } else if (mx3 < (1 + dp1[x])) {
      mx3 = 1 + dp1[x];
      ind3[i] = ind1[x];
    }
  }
  dp1[i] = mx1;
  dp2[i] = mx2;
  dp3[i] = mx3;
}
void dfs2(int i, int par) {
  multiset<pair<int, int> > s;
  s.insert(make_pair(up[i], u_ind[i]));
  for (auto x : adj[i]) {
    if (x != par) s.insert(make_pair(1 + dp1[x], ind1[x]));
  }
  for (auto x : adj[i]) {
    if (x == par) continue;
    s.erase(s.find(make_pair(1 + dp1[x], ind1[x])));
    pair<int, int> z = (*s.rbegin());
    up[x] = 1 + z.first;
    u_ind[x] = z.second;
    dfs2(x, i);
    s.insert(make_pair(1 + dp1[x], ind1[x]));
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i < n; i++) {
      int x, y;
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    dfs(1, 0);
    u_ind[1] = 1;
    dfs2(1, 0);
    int ans = 0;
    int x1 = 0, x2 = 0, x3 = 0;
    for (int i = 1; i <= n; i++) {
      if ((up[i] + dp1[i] + dp2[i]) > ans) {
        ans = up[i] + dp1[i] + dp2[i];
        x1 = ind1[i], x2 = ind2[i], x3 = u_ind[i];
      }
      if ((dp3[i] + dp1[i] + dp2[i]) > ans) {
        ans = dp3[i] + dp1[i] + dp2[i];
        x1 = ind1[i], x2 = ind2[i], x3 = ind3[i];
      }
    }
    cout << ans << endl;
    set<int> s;
    s.insert(x1);
    s.insert(x2);
    s.insert(x3);
    if (s.size() < 3) {
      for (int i = 1; i <= n; i++) {
        if (s.find(i) == s.end()) {
          s.insert(i);
          break;
        }
      }
    }
    for (auto x : s) {
      cout << x << " ";
    }
    cout << endl;
  }
  return 0;
}
