#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
vector<int> E[maxn];
vector<int> s;
bool vis[maxn];
int n, u, v, root, big, dian, dian1;
int as = 0;
int fa[maxn];
void dfs_fid(int u, int step) {
  if (step > big) {
    big = step;
    root = u;
  }
  vis[u] = 1;
  for (auto v : E[u]) {
    if (vis[v]) continue;
    dfs_fid(v, step + 1);
  }
}
void dfs(int u, int fa1, int step) {
  if (step == 1) dian1 = u;
  fa[u] = fa1;
  vis[u] = 1;
  if (step >= big) {
    dian = u;
    big = step;
  }
  for (auto v : E[u]) {
    if (vis[v]) continue;
    dfs(v, u, step + 1);
  }
}
void dfs1(int u, int step) {
  if (step > as) {
    dian1 = u;
    as = step;
  }
  vis[u] = 1;
  for (auto v : E[u]) {
    if (vis[v]) continue;
    dfs1(v, step + 1);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    cin >> u >> v;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  vis[1] = 1;
  dfs_fid(1, 0);
  memset(vis, 0, sizeof(vis));
  dfs(root, 0, 0);
  memset(vis, 0, sizeof(vis));
  int now = dian, ans = 0;
  vis[now] = 1;
  while (fa[now] != 0) {
    vis[now] = 1;
    now = fa[now];
    s.push_back(now);
    ans++;
  }
  vis[now] = 1;
  for (auto i : s) {
    dfs1(i, 0);
  }
  cout << ans + as << '\n';
  cout << root << " " << dian << " " << dian1;
  return 0;
}
