#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, LOG = 20;
int n;
vector<int> g[N];
int h[N], up[LOG][N];
pair<int, int> mx[2][N];
vector<int> leaves;
void dfs(int v, int p) {
  up[0][v] = p;
  for (int i = 1; i < LOG; ++i) {
    up[i][v] = up[i - 1][up[i - 1][v]];
  }
  mx[0][v] = make_pair(0, v);
  mx[1][v] = make_pair(0, v);
  bool is_leaf = true;
  for (int &u : g[v]) {
    if (u == p) {
      continue;
    }
    is_leaf = false;
    h[u] = h[v] + 1;
    dfs(u, v);
    if (mx[0][v].first <= mx[0][u].first + 1) {
      mx[1][v] = mx[0][v];
      mx[0][v].first = mx[0][u].first + 1;
      mx[0][v].second = mx[0][u].second;
    } else if (mx[1][v].first < mx[0][u].first + 1) {
      mx[1][v].first = mx[0][u].first + 1;
      mx[1][v].second = mx[0][u].second;
    }
  }
  if (is_leaf) {
    leaves.push_back(v);
  }
}
int getLA(int v, int k) {
  for (int i = 0; i < LOG; ++i) {
    if ((k >> i) & 1) {
      v = up[i][v];
    }
  }
  return v;
}
int getLCA(int v, int u) {
  if (h[v] < h[u]) {
    u = getLA(u, h[u] - h[v]);
  }
  if (h[u] < h[v]) {
    v = getLA(v, h[v] - h[u]);
  }
  if (v == u) {
    return v;
  }
  for (int i = LOG - 1; i > -1; --i) {
    int v1 = up[i][v], u1 = up[i][u];
    if (v1 != u1) {
      v = v1;
      u = u1;
    }
  }
  return up[0][v];
}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
signed main() {
  if (strlen("") > 0)
    freopen(
        ""
        ".in",
        "r", stdin),
        freopen(
            ""
            ".out",
            "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    cin >> v >> u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  dfs(1, 1);
  vector<pair<pair<int, int>, int>> vars;
  for (int i = 1; i <= n; ++i) {
    int curr_len = mx[0][i].first + mx[1][i].first;
    if (curr_len > 0) {
      vars.push_back(make_pair(make_pair(curr_len, h[i]), i));
    }
  }
  sort(vars.rbegin(), vars.rend());
  pair<pair<int, int>, pair<int, int>> answ;
  for (int idx = 0; idx < min(5, (int)vars.size()); ++idx) {
    int a = mx[0][vars[idx].second].second, b = mx[1][vars[idx].second].second,
        lca = getLCA(a, b);
    pair<int, int> curr = make_pair(0, 0);
    for (int i = 1; i <= n; ++i) {
      if (a != i && b != i) {
        curr.second = i;
        break;
      }
    }
    for (int &c : leaves) {
      if (a == c || b == c) {
        continue;
      }
      int lll = getLCA(lca, c);
      if (lll == lca) {
        int A = getLCA(a, c), B = getLCA(b, c);
        if (A == lca && B == lca) {
          curr = max(curr, make_pair(h[c] - h[lca], c));
        } else if (A == lca) {
          curr = max(curr, make_pair(h[c] - h[B], c));
        } else {
          curr = max(curr, make_pair(h[c] - h[A], c));
        }
      } else {
        curr = max(curr, make_pair(h[lll] - h[c] + h[lll] - h[lca], c));
      }
    }
    answ = max(answ, make_pair(make_pair(curr.first + vars[idx].first.first, a),
                               make_pair(b, curr.second)));
  }
  cout << answ.first.first << "\n"
       << answ.first.second << " " << answ.second.first << " "
       << answ.second.second << "\n";
  return 0;
}
