#include <bits/stdc++.h>
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
const int K = 20;
using namespace std;
int n, mx, node, cr;
vector<int> lst[N];
int par[N], dis[N];
void dfs(int u, int p = -1, int d = 0) {
  if (d > mx) {
    node = u;
    mx = d;
  }
  par[u] = p;
  dis[u] = d;
  for (auto v : lst[u])
    if (v != p) dfs(v, u, d + 1);
}
void dfs1(int u, int p) {
  if (dis[u] > cr) {
    cr = dis[u];
    node = u;
  }
  for (auto v : lst[u])
    if (v != p) dfs1(v, u);
}
void solve() {
  cin >> n;
  for (int i = 1; i < n; i += 1) {
    int u, v;
    cin >> u >> v;
    lst[--u].push_back(--v);
    lst[v].push_back(u);
  }
  int a, b, c = -1, ans, prev = -1, temp;
  mx = 0;
  dfs(0);
  a = node;
  mx = 0;
  dfs(a);
  b = temp = node;
  ans = mx;
  mx = 0;
  while (temp != -1) {
    for (auto v : lst[temp])
      if (v != par[temp] && v != prev) {
        cr = 0;
        dfs1(v, temp);
        if (mx < (cr - dis[temp])) {
          c = node;
          mx = cr - dis[temp];
        }
      }
    prev = temp;
    temp = par[temp];
  }
  ans += mx;
  if (c == -1) c = par[b];
  cout << ans << "\n" << (a + 1) << ' ' << (b + 1) << ' ' << (c + 1);
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
