#include <cstdio>
#include <vector>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back

#define m 100100

vector <int> c[m];
int n, u[m], nu[m];

int dfs( int v, int p, int d )
{
  u[v] = 2;
  if (v == d)
    return 0;
  forn (i, c[v].size())
    if (c[v][i] != p && u[c[v][i]] == 0)
    {
      int t = dfs(c[v][i], v, d);
      if (t != -1)
        return t + 1;
    }
  u[v] = 1;
  return -1;
}

int main()
{
  freopen("collider.in", "r", stdin);
  freopen("collider.out", "w", stdout);
  scanf("%d", &n);
  forn (i, n - 1)
  {
    int a, b;
    scanf("%d%d", &a, &b), a--, b--;
    c[a].pb(b), c[b].pb(a);
  }
  int a1 = -1, a2 = -1, a3 = -1, a4 = -1, ans = -1;
  forn (v1, n) forn (v2, v1)
  {
    forn (i, n)
      u[i] = 0;
    int t = dfs(v1, -1, v2);
    if (t + 1 > ans)
      ans = t + 1, a1 = v1, a2 = v2;
  }
  forn (v0, n) forn (v1, v0) forn (v2, n) forn (v3, v2)
  {
//    fprintf(stderr, "%d %d %d %d\n", v0, v1, v2, v3);
    int t1, t2, be = -1;
    bool ok;
    forn (tt, 2)
    {
      forn (i, n)
        u[i] = 0;
      forn (i, n)
        nu[i] = 0;
      t1 = dfs(v0, -1, v2);
      forn (i, n)
        if (u[i] == 2 && i != v0 && i != v2)
          nu[i]++;
      forn (i, n)
        u[i] = 0;
      t2 = dfs(v3, -1, v1);
      forn (i, n)
        if (u[i] == 2 && i != v1 && i != v3)
          nu[i]++;
      ok = t1 != -1 && t2 != -1;
      forn (i, n)
        if (nu[i] > 1)
          ok = false;
      if (nu[v0] > 0 || nu[v1] > 0 || nu[v2] > 0 || nu[v3] > 0)
        ok = false;
//      forn (i, n)
//        fprintf(stderr, "nu[%d]=%d\n", i + 1, nu[i]);
      if (ok && (be < t1 + t2 + 2))
        be = t1 + t2 + 2;
//      fprintf(stderr, "%d\n", be);
      swap(v2, v3);
    }

    if (be > ans)
      ans = be, a1 = v0, a2 = v1, a3 = v2, a4 = v3;
  }
  printf("%d\n%d %d\n", ans, a1 + 1, a2 + 1);
  if (a3 != -1)
    printf("%d %d\n", a3 + 1, a4 + 1);
  return 0;
}
