#include <bits/stdc++.h>
using namespace std;
int const mod = 998244353;
int const inf = 2e18;
inline int add(int a, int b) { return (a % mod + b % mod + mod) % mod; }
inline int mul(int a, int b) { return (a % mod * b % mod + mod) % mod; }
inline int sub(int a, int b) { return (a % mod - b % mod + mod) % mod; }
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int modexp(int x, int n) {
  if (n == 0) {
    return 1;
  } else if (n & 1) {
    return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;
  } else {
    return (modexp((x * x) % mod, n / 2) % mod);
  }
}
int modinv(int n) { return modexp(n, mod - 2); }
template <class T>
void dispvector(vector<T> v) {
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
const int N = 2e5 + 5;
vector<int> g[N];
int n;
bool ok = 0;
struct item {
  int htl;
  int dial;
  int de1;
  int de2;
  int he1;
};
item dfs(int v, int pa) {
  int dial = 0;
  int ht1 = 0;
  int ht2 = 0;
  int he1 = v;
  int he2 = v;
  int de1 = v;
  int de2 = v;
  for (int u : g[v]) {
    if (u != pa) {
      item rem = dfs(u, v);
      if (rem.htl >= ht1) {
        ht2 = ht1;
        he2 = he1;
        ht1 = rem.htl;
        he1 = rem.he1;
      } else if (rem.htl > ht2) {
        ht2 = rem.htl;
        he2 = rem.he1;
      }
      if (rem.dial > dial) {
        dial = rem.dial;
        de1 = rem.de1;
        de2 = rem.de2;
      }
    }
  }
  if (ht1 + ht2 + 1 > dial) {
    dial = ht1 + ht2 + 1;
    de1 = he1;
    de2 = he2;
  }
  if (ht1 > ht2) {
    return {ht1 + 1, dial, de1, de2, he1};
  } else {
    return {ht2 + 1, dial, de1, de2, he2};
  }
}
void dfs2(int v, int pa, set<int>& mydia, int cht, int& ht, int& rr) {
  if (cht > ht) {
    ht = cht;
    rr = v;
  }
  for (int u : g[v]) {
    if (u != pa && !mydia.count(u)) {
      dfs2(u, v, mydia, cht + 1, ht, rr);
    }
  }
}
void dfs3(int v, int pa, int& t, set<int>& mydia) {
  if (v == t) {
    mydia.insert(v);
    ok = 1;
    return;
  }
  for (int u : g[v]) {
    if (u != pa) {
      mydia.insert(v);
      dfs3(u, v, t, mydia);
      if (ok) return;
      mydia.erase(v);
    }
  }
}
void solve() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int root = -1;
  for (int i = 1; i < n + 1; i++) {
    if (g[i].size() == 1) root = i;
  }
  int ans = 0;
  item rem = dfs(root, root);
  int v1 = rem.de1;
  int v2 = rem.de2;
  set<int> mydia;
  dfs3(v1, v1, v2, mydia);
  ans += rem.dial;
  int mx = 0;
  int mxv = 0;
  for (int i = 1; i < n + 1; i++) {
    if (mydia.count(i)) {
      int ht = 0;
      int rr = i;
      dfs2(i, i, mydia, 0, ht, rr);
      if (ht > mx) {
        mx = ht;
        mxv = rr;
      }
    }
  }
  ans += mx;
  cout << ans - 1 << "\n";
  cout << v1 << " " << v2 << " ";
  if (mx != 0) {
    cout << mxv << "\n";
  } else {
    for (int i = 1; i < n + 1; i++) {
      if (i != v1 && i != v2) {
        cout << i << "\n";
        break;
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  for (int i = 1; i <= tc; i++) {
    solve();
  }
  return 0;
}
