#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long MOD = 1e9 + 7;
const long long MAX_N = 1e5;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long vis[200005];
vector<long long> v[200005];
long long h[200005];
long long p[200005];
bool yata[200005];
void dfs(long long ini) {
  vis[ini] = 1;
  for (int i = 0; i < v[ini].size(); i++) {
    long long vecino = v[ini][i];
    if (!vis[vecino]) {
      h[vecino] = h[ini] + 1;
      dfs(vecino);
    }
  }
}
void dfs1(long long ini) {
  vis[ini] = 1;
  for (int i = 0; i < v[ini].size(); i++) {
    long long vecino = v[ini][i];
    if (!vis[vecino]) {
      h[vecino] = h[ini] + 1;
      p[vecino] = ini;
      dfs1(vecino);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1);
  vector<pair<long long, long long> > ga;
  for (int i = 1; i < n + 1; i++) {
    ga.push_back(make_pair(h[i], i));
  }
  sort(ga.rbegin(), ga.rend());
  long long punto = ga[0].second;
  memset(vis, 0, sizeof(vis));
  memset(h, 0, sizeof(h));
  dfs(punto);
  ga.clear();
  for (int i = 1; i < n + 1; i++) {
    ga.push_back(make_pair(h[i], i));
  }
  sort(ga.rbegin(), ga.rend());
  long long punto2;
  for (int i = 0; i < ga.size(); i++) {
    if (ga[i].second != punto) {
      punto2 = ga[i].second;
      break;
    }
  }
  long long cur;
  memset(vis, 0, sizeof(vis));
  memset(h, 0, sizeof(h));
  dfs1(punto);
  long long ans2 = 0;
  long long aux = punto, aux1 = punto2;
  aux1 = punto2;
  yata[punto] = 1;
  yata[punto2] = 1;
  while (aux1 != punto) {
    aux1 = p[aux1];
    yata[aux1] = 1;
  }
  ga.clear();
  for (int i = 1; i < n + 1; i++) {
    ga.push_back(make_pair(h[i], i));
  }
  sort(ga.rbegin(), ga.rend());
  long long punto3 = 1;
  long long flag = 0;
  vector<long long> posibles;
  for (int i = 1; i < n + 1; i++) {
    if (yata[i] == 0) posibles.push_back(i);
  }
  vector<pair<long long, long long> > val;
  if (posibles.size() != 0) {
    long long cont = 0;
    for (int i = 0; i < posibles.size(); i++) {
      long long au = posibles[i];
      cont = 0;
      while (yata[au] == 0) {
        au = p[au];
        cont++;
      }
      val.push_back(make_pair(cont, posibles[i]));
    }
    if (val.size() != 0) {
      sort(val.rbegin(), val.rend());
      punto3 = val[0].second;
      ans2 += val[0].first;
      flag = 1;
    }
  }
  long long ans1 = 0;
  memset(vis, 0, sizeof(vis));
  memset(h, 0, sizeof(h));
  memset(p, 0, sizeof(p));
  for (int i = 1; i < n + 1; i++) {
    if (i != punto && i != punto2) {
      cur = i;
      break;
    }
  }
  dfs(punto);
  if (flag == 1)
    ans1 = h[punto2] + val[0].first;
  else
    ans1 = h[punto2];
  cout << ans1 << endl;
  if (flag == 1)
    cout << punto << " " << punto2 << " " << punto3 << endl;
  else
    cout << punto << " " << punto2 << " " << cur << endl;
  return 0;
}
