#include <bits/stdc++.h>
using namespace std;
vector<long long> ft(1, 1LL);
int n, ans[3], hg, xxx = 0;
vector<int> graph[200005], vis(200005);
queue<int> q;
void dfs(int node, int par, int i, int h) {
  if (h >= hg) hg = h, ans[i] = node;
  for (auto child : graph[node])
    if (child != par) dfs(child, node, i, h + 1);
}
int dfs2(int node, int par, int dest) {
  if (node == dest) {
    q.push(node);
    vis[node] = 1;
    return 1;
  }
  for (auto child : graph[node]) {
    if (child == par) continue;
    if (dfs2(child, node, dest)) {
      q.push(node), vis[node] = 1;
      return 1;
    }
  }
  return 0;
}
void solve() {
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    int node1, node2;
    cin >> node1 >> node2;
    graph[node1].push_back(node2), graph[node2].push_back(node1);
  }
  dfs(1, 0, 0, 0);
  hg = 0;
  dfs(ans[0], 0, 1, 0);
  xxx = hg;
  dfs2(ans[0], 0, ans[1]);
  hg = 0;
  while (q.size()) {
    int p = q.front();
    if (vis[p] >= hg and p != ans[0] and p != ans[1]) hg = vis[p], ans[2] = p;
    q.pop();
    for (auto child : graph[p]) {
      if (vis[child] == 0) vis[child] = vis[p] + 1, q.push(child);
    }
  }
  cout << xxx + hg - 1 << '\n';
  cout << ans[1] << " " << ans[2] << " " << ans[0];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
}
