#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int binpow(long long int z, long long int n) {
  if (n == 0) return 1;
  if (n % 2 == 1)
    return (binpow(z, n - 1) * z) % mod;
  else
    return (binpow(z, n / 2) * binpow(z, n / 2)) % mod;
}
bool isvalid(long long int x, long long int y,
             vector<vector<long long int> > &a) {
  long long int n = a.size();
  long long int m = a[0].size();
  if (x < 0 || x >= n || y < 0 || y >= m)
    return 0;
  else
    return 1;
}
void multibfs(vector<vector<long long int> > &a, vector<long long int> &vis,
              queue<long long int> &v) {
  long long int x, y;
  while (!v.empty()) {
    long long int p = v.front();
    v.pop();
    for (long long int i = 0; i < (a[p].size()); i++) {
      long long int z = a[p][i];
      if (vis[z] != -1) continue;
      vis[z] = vis[p] + 1;
      v.push(z);
    }
  }
}
void dfslev(long long int x, long long int par,
            vector<vector<long long int> > &a, vector<long long int> &lev) {
  for (long long int i = 0; i < (a[x].size()); i++) {
    long long int z = a[x][i];
    if (z == par) continue;
    lev[z] = lev[x] + 1;
    dfslev(z, x, a, lev);
  }
}
long long int path(long long int x, long long int par, long long int tar,
                   vector<vector<long long int> > &a,
                   vector<long long int> &vis, queue<long long int> &v) {
  if (x == tar) {
    vis[x] = 0;
    v.push(x);
    return 1;
  }
  for (long long int i = 0; i < (a[x].size()); i++) {
    long long int z = a[x][i];
    if (z == par) continue;
    long long int val = path(z, x, tar, a, vis, v);
    if (val == 1) {
      vis[x] = 0;
      v.push(x);
      return 1;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  long long int t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    vector<vector<long long int> > a(n);
    long long int x, y, z, w, u, res = 0;
    for (long long int i = 0; i < ((n - 1)); i++) {
      cin >> x >> y;
      a[x - 1].push_back(y - 1);
      a[y - 1].push_back(x - 1);
    }
    vector<long long int> lev(n, 0);
    vector<long long int> vis(n, -1);
    dfslev(0, 0, a, lev);
    long long int maxi = 0;
    for (long long int i = 0; i < (n); i++) {
      if (lev[i] > maxi) {
        maxi = lev[i];
        z = i;
      }
    }
    lev = vector<long long int>(n, 0);
    dfslev(z, z, a, lev);
    maxi = 0;
    for (long long int i = 0; i < (n); i++) {
      if (lev[i] > maxi) {
        maxi = lev[i];
        w = i;
      }
    }
    res += lev[w];
    queue<long long int> v;
    long long int none = path(z, z, w, a, vis, v);
    multibfs(a, vis, v);
    maxi = 0;
    for (long long int i = 0; i < (n); i++) {
      if (vis[i] >= maxi && i != w && i != z) {
        maxi = vis[i];
        u = i;
      }
    }
    res += vis[u];
    cout << res << "\n";
    cout << u + 1 << " " << z + 1 << " " << w + 1 << "\n";
  }
}
