#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long inf = 1LL << 50;
const int N = 200000;
vector<vector<int>> tree(N + 5);
vector<deque<pair<int, int>>> bigs(N + 5);
int one, two, three;
int ans = 0;
void dfs2(int curr, int par, int best, int ind) {
  if (tree[curr].size() == 1) {
    for (int i : tree[curr]) {
      if (i != par) {
        dfs2(i, curr, best + 1, ind);
      }
    }
    return;
  }
  if (bigs[curr].size() == 3) {
    if (ans < bigs[curr][0].first + bigs[curr][1].first + bigs[curr][2].first) {
      ans = bigs[curr][0].first + bigs[curr][1].first + bigs[curr][2].first;
      one = bigs[curr][0].second;
      two = bigs[curr][1].second;
      three = bigs[curr][2].second;
    };
  }
  if (ans < bigs[curr][0].first + bigs[curr][1].first + best) {
    ans = bigs[curr][0].first + bigs[curr][1].first + best;
    one = bigs[curr][0].second;
    two = bigs[curr][1].second;
    three = ind;
  };
  for (int i : tree[curr]) {
    if (i != par) {
      if (bigs[i][0].first + 1 == bigs[curr][0].first) {
        if (best + 1 > bigs[curr][1].first + 1) {
          dfs2(i, curr, best + 1, ind);
        } else {
          dfs2(i, curr, bigs[curr][1].first + 1, bigs[curr][1].second);
        }
      } else {
        if (best + 1 > bigs[curr][0].first + 1) {
          dfs2(i, curr, best + 1, ind);
        } else {
          dfs2(i, curr, bigs[curr][0].first + 1, bigs[curr][0].second);
        }
      }
    }
  }
}
void dfs(int curr, int par) {
  for (int i : tree[curr]) {
    if (i != par) {
      dfs(i, curr);
      if (bigs[curr].size() < 3) {
        if (bigs[curr].size() == 0) {
          bigs[curr].emplace_back(bigs[i][0].first + 1, bigs[i][0].second);
        } else if (bigs[curr].size() == 1) {
          if (bigs[i][0].first + 1 > bigs[curr][0].first) {
            bigs[curr].emplace_front(bigs[i][0].first + 1, bigs[i][0].second);
          } else {
            bigs[curr].emplace_back(bigs[i][0].first + 1, bigs[i][0].second);
          }
        } else {
          if (bigs[i][0].first + 1 > bigs[curr][0].first) {
            bigs[curr].emplace_front(bigs[i][0].first + 1, bigs[i][0].second);
          } else if (bigs[curr][1].first < bigs[i][0].first + 1) {
            bigs[curr].emplace_back();
            bigs[curr][2] = bigs[curr][1];
            bigs[curr][1].first = bigs[i][0].first + 1;
            bigs[curr][1].second = bigs[i][0].second;
          } else {
            bigs[curr].emplace_back(bigs[i][0].first + 1, bigs[i][0].second);
          }
        }
      } else {
        if (bigs[curr][0].first < bigs[i][0].first + 1) {
          bigs[curr].emplace_front(bigs[i][0].first + 1, bigs[i][0].second);
          bigs[curr].pop_back();
        } else if (bigs[curr][1].first < bigs[i][0].first + 1) {
          bigs[curr][2] = bigs[curr][1];
          bigs[curr][1].first = bigs[i][0].first + 1;
          bigs[curr][1].second = bigs[i][0].second;
        } else if (bigs[curr][2].first < bigs[i][0].first + 1) {
          bigs[curr][2].first = bigs[i][0].first + 1;
          bigs[curr][2].second = bigs[i][0].second;
        }
      }
    }
  }
  if (bigs[curr].size() < 3) {
    bigs[curr].emplace_back(0, curr);
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin.exceptions(cin.failbit);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  dfs(0, -1);
  if (tree[0].size() == 1) {
    dfs2(tree[0][0], 0, 1, 0);
  } else {
    if (bigs[0].size() == 3) {
      if (ans < bigs[0][0].first + bigs[0][1].first + bigs[0][2].first) {
        ans = bigs[0][0].first + bigs[0][1].first + bigs[0][2].first;
        one = bigs[0][0].second;
        two = bigs[0][1].second;
        three = bigs[0][2].second;
      }
    }
    for (int i : tree[0]) {
      if (bigs[i][0].first + 1 == bigs[0][0].first) {
        dfs2(i, 0, bigs[0][1].first + 1, bigs[0][1].second);
      } else {
        dfs2(i, 0, bigs[0][0].first + 1, bigs[0][0].second);
      }
    }
  }
  cout << ans << "\n";
  cout << one + 1 << " " << two + 1 << " " << three + 1 << "\n";
}
