#include <bits/stdc++.h>
using namespace std;
const int maxN = 1 << 18;
struct node {
  bool diam = false, seen = false;
  vector<int> N;
  int h = 0, p = -1;
} G[maxN];
pair<int, int> DFS(int v, bool shams = false, int w = -1) {
  if (w > -1) G[v].h = G[w].h + 1;
  if (shams) G[v].p = w;
  pair<int, int> DL = {G[v].h, v};
  for (int u : G[v].N)
    if (u != w) DL = max(DL, DFS(u, shams, v));
  return DL;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    G[v].N.push_back(u);
    G[u].N.push_back(v);
  }
  int a = DFS(1).second;
  G[a].h = 0;
  int b = DFS(a, true).second;
  vector<int> D;
  queue<int> Q;
  for (int v = b; v != a; v = G[v].p) {
    D.push_back(v);
    Q.push(v);
    G[v].seen = G[v].diam = true;
  }
  D.push_back(a);
  Q.push(a);
  G[a].seen = G[a].diam = true;
  if (D.size() == n)
    return cout << n - 1 << "\n" << a << " " << b << " " << D[1], 0;
  int c = -2;
  while (Q.size()) {
    for (int u : G[Q.front()].N)
      if (!G[u].seen) {
        Q.push(u);
        G[u].seen = true;
      }
    c = Q.front();
    Q.pop();
  }
  for (int v = c; !G[v].diam; v = G[v].p) D.push_back(v);
  cout << D.size() - 1 << "\n" << a << " " << b << " " << c;
}
