#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 5;
vector<int> g[nax], p(nax, -1), d(nax, 0);
void dfs(int s, int from) {
  p[s] = from;
  for (auto it : g[s]) {
    if (it != from) {
      d[it] = d[s] + 1;
      dfs(it, s);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, -1);
  int ans = 0;
  int a = 1, b = -1, c = -1;
  for (long long i = 1; i < n + 1; i++) {
    if (d[i] > d[a]) a = i;
  }
  d.assign(n + 1, 0);
  dfs(a, -1);
  for (long long i = 1; i < n + 1; i++)
    if (b == -1 || d[i] > d[b]) b = i;
  ans += d[b];
  queue<int> q;
  vector<int> vis(n + 1, 0), d1(n + 1, 0);
  int z = b;
  while (z != -1) {
    q.push(z);
    vis[z] = 1;
    z = p[z];
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto it : g[v]) {
      if (!vis[it]) {
        vis[it] = 1;
        q.push(it);
        d1[it] = d1[v] + 1;
      }
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    if (i != a && i != b && (c == -1 || (d1[i] > d1[c]))) c = i;
  }
  cout << ans + d1[c] << "\n";
  cout << a << " " << b << " " << c;
  return 0;
}
