#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void fio() {}
void pti() {
  double timeuse = clock() * 1000.0 / CLOCKS_PER_SEC;
  cerr << "Timeuse " << timeuse << "ms" << endl;
}
void end() {
  pti();
  exit(0);
}
namespace io {
const int SIZ = 55;
int que[SIZ], op, qr;
char ch;
template <class I>
inline void gi(I &w) {
  ch = getchar(), op = 1, w = 0;
  while (!isdigit(ch)) {
    if (ch == '-') op = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    w = w * 10 + ch - '0';
    ch = getchar();
  }
  w *= op;
}
template <class I>
inline void print(I w) {
  qr = 0;
  if (!w) putchar('0');
  if (w < 0) putchar('-'), w = -w;
  while (w) que[++qr] = w % 10 + '0', w /= 10;
  while (qr) putchar(que[qr--]);
}
}  // namespace io
using io::gi;
using io::print;
const int N = 2e5 + 5;
struct EDGE {
  int to, nxt;
};
int n, cnt, maxd, rt1, rt2, rt3, ans;
int head[N], rev[N], anc[N];
EDGE e[N * 2];
void add(int x, int y) {
  e[++cnt].to = y;
  e[cnt].nxt = head[x];
  head[x] = cnt;
}
void link(int x, int y) { add(x, y), add(y, x); }
void dfs1(int x, int fa, int d) {
  if (d > maxd) maxd = d, rt1 = x;
  for (int i = head[x]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs1(v, x, d + 1);
  }
}
void dfs2(int x, int fa, int d) {
  if (d > maxd) maxd = d, rt2 = x, ans = d;
  anc[x] = fa;
  for (int i = head[x]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs2(v, x, d + 1);
  }
}
void calc(int x, int d) {
  if (d > maxd) maxd = d, rt3 = x;
  for (int i = head[x]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == anc[x] || v == rev[x]) continue;
    calc(v, d + 1);
  }
}
int main() {
  fio();
  gi(n);
  for (int i = 1, x, y; i <= n - 1; ++i) gi(x), gi(y), link(x, y);
  dfs1(1, 0, 0), maxd = 0;
  dfs2(rt1, 0, 0), maxd = 0;
  int x = rt2, res = 0;
  while (x) {
    rev[anc[x]] = x;
    calc(x, 0);
    x = anc[x];
  }
  print(ans + maxd), putchar(10);
  print(rt1), putchar(' '), print(rt2), putchar(' ');
  if (!rt3)
    for (int i = 1; i <= n; ++i)
      if (i != rt1 && i != rt2) rt3 = i;
  print(rt3);
  end();
}
