#include <bits/stdc++.h>
using namespace std;
long long int bg = 9982443530987;
vector<vector<long long int> > vec(400000), newvec(400000);
set<pair<long long int, long long int> > vec1;
set<long long int> set1;
long long int vis[400000], f[400000], f2[400000];
void dfs(long long int i, long long int k) {
  long long int j, s = 0;
  vis[i] = 1;
  f[i] = k;
  for (j = 0; j < vec[i].size(); j++) {
    if (vis[vec[i][j]] == 0) dfs(vec[i][j], k + 1);
  }
}
void dfs2(long long int i, long long int k) {
  long long int j, s = 0;
  vis[i] = 1;
  f2[i] = k;
  for (j = 0; j < vec[i].size(); j++) {
    if (vis[vec[i][j]] == 0) dfs2(vec[i][j], k + 1);
  }
}
int dfs3(long long int i, long long int b) {
  long long int j, s = 0;
  vis[i] = 1;
  for (j = 0; j < vec[i].size(); j++) {
    if (vis[vec[i][j]] == 0) {
      long long int h = dfs3(vec[i][j], b), a = min(i, vec[i][j]),
                    b = max(i, vec[i][j]);
      s += h;
      if (h == 1) {
        vec1.insert(make_pair(a, b));
        set1.insert(a);
        set1.insert(b);
      }
    }
  }
  if (i == b || s > 0)
    return 1;
  else
    return 0;
}
pair<long long int, long long int> dfs4(long long int i) {
  long long int j, s = 0;
  vis[i] = 1;
  vector<pair<long long int, long long int> > gg;
  for (j = 0; j < newvec[i].size(); j++) {
    if (vis[newvec[i][j]] == 0) gg.push_back(dfs4(newvec[i][j]));
  }
  sort(gg.begin(), gg.end());
  if (gg.size() == 0)
    return make_pair(1, i);
  else
    return make_pair(gg[gg.size() - 1].first + 1, gg[gg.size() - 1].second);
}
void boom() {
  long long int i, n, h = bg, j, m, k;
  cin >> n;
  for (i = 0; i < n - 1; i++) {
    long long int a, b;
    cin >> a >> b;
    vec[a - 1].push_back(b - 1);
    vec[b - 1].push_back(a - 1);
  }
  dfs(0, 1);
  long long int a = 0, dis1 = 0;
  for (i = 0; i < n; i++) {
    if (dis1 <= f[i]) {
      a = i;
      dis1 = f[i];
    }
  }
  for (i = 0; i < n; i++) vis[i] = 0;
  dfs2(a, 1);
  long long int b = 0, dis2 = 0;
  for (i = 0; i < n; i++) {
    if (dis2 <= f2[i] && i != a) {
      b = i;
      dis2 = f2[i];
    }
  }
  for (i = 0; i < n; i++) vis[i] = 0;
  int y = dfs3(a, b);
  for (i = 0; i < n; i++) {
    for (j = 0; j < vec[i].size(); j++) {
      long long int h1 = min(i, vec[i][j]), h2 = max(i, vec[i][j]);
      if (vec1.find(make_pair(h1, h2)) == vec1.end())
        newvec[i].push_back(vec[i][j]);
    }
  }
  set<long long int>::iterator yy = set1.begin();
  vector<pair<long long int, long long int> > final;
  for (i = 0; i < n; i++) vis[i] = 0;
  for (; yy != set1.end(); yy++) {
    pair<long long int, long long int> dd = dfs4(*yy);
    final.push_back(dd);
  }
  sort(final.begin(), final.end());
  cout << dis2 + final[final.size() - 1].first - 2 << '\n';
  for (i = final.size() - 1; i >= 0; i--)
    if (final[i].second != a && final[i].second != b) {
      cout << a + 1 << " " << b + 1 << " " << final[i].second + 1;
      break;
    }
}
int main() {
  long long int t;
  t = 1;
  while (t--) boom();
  return 0;
}
