#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200005];
int n, d[200005], p[200005];
bool del[200005];
void dfs(int nw, int bf) {
  d[nw] = d[bf] + 1;
  p[nw] = bf;
  for (int nxt : adj[nw])
    if (nxt != bf) dfs(nxt, nw);
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1, u, v; i < n; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int a = 0, b = 0, c = 0;
  memset(d, 0, sizeof(d));
  dfs(1, 0);
  for (int i = 1; i <= n; i++)
    if (d[a] < d[i]) a = i;
  memset(d, 0, sizeof(d));
  dfs(a, 0);
  for (int i = 1; i <= n; i++)
    if (d[b] < d[i]) b = i;
  int ans = d[b] - 1;
  int x = b;
  while (x) {
    del[x] = true;
    x = p[x];
  }
  x = b;
  memset(d, 0, sizeof(d));
  while (x) {
    for (int i : adj[x]) {
      if (!del[i]) dfs(i, x);
    }
    x = p[x];
  }
  for (int i = 1; i <= n; i++)
    if (i != a && i != b && d[c] <= d[i]) c = i;
  cout << d[c] + ans << endl;
  cout << a << " " << b << " " << c << endl;
  return 0;
}
