#include <bits/stdc++.h>
using namespace std;
int deep[200200], dp[200200], dp2[200200], num[200200], pre[200200];
vector<pair<int, int> > dp2Ans(200200);
vector<pair<int, pair<int, int> > > ans(200200);
vector<vector<int> > g(200200);
int n, f, f1;
pair<int, pair<int, int> > w;
void build(int ver, int p = -1) {
  deep[ver] = 1;
  pre[ver] = p;
  num[ver] = ver;
  for (int i = 0; i < g[ver].size(); i++) {
    int to = g[ver][i];
    if (to != p) {
      build(to, ver);
      if (deep[to] + 1 > deep[ver]) {
        deep[ver] = deep[to] + 1;
        num[ver] = num[to];
      }
    }
  }
}
void dfs(int ver, int p = -1) {
  vector<int> pref(g[ver].size() + 5, 0);
  vector<int> suf(g[ver].size() + 5, 0);
  vector<int> posPref(g[ver].size() + 5, 0);
  vector<int> posSuf(g[ver].size() + 5, 0);
  pref[0] = suf[g[ver].size() + 1] = 0;
  for (int i = 1; i <= g[ver].size(); i++) {
    if (pref[i - 1] < deep[g[ver][i - 1]] && g[ver][i - 1] != p) {
      pref[i] = deep[g[ver][i - 1]];
      posPref[i] = num[g[ver][i - 1]];
    } else {
      pref[i] = pref[i - 1];
      posPref[i] = posPref[i - 1];
    }
  }
  for (int i = g[ver].size(); i >= 1; i--) {
    if (suf[i + 1] < deep[g[ver][i - 1]] && g[ver][i - 1] != p) {
      suf[i] = deep[g[ver][i - 1]];
      posSuf[i] = num[g[ver][i - 1]];
    } else {
      suf[i] = suf[i + 1];
      posSuf[i] = posSuf[i + 1];
    }
  }
  set<pair<int, int> > s;
  for (int i = 0; i < g[ver].size(); i++) {
    int to = g[ver][i];
    if (to != p) {
      s.insert({deep[to], num[to]});
      if (s.size() == 3) {
        s.erase(s.begin());
      }
    }
  }
  if (s.size() == 1) {
    dp2[ver] = (*s.begin()).first;
    dp2Ans[ver].first = (*s.begin()).second;
    dp2Ans[ver].second = pre[dp2Ans[ver].first];
  }
  if (s.size() == 2) {
    dp2[ver] = (*s.begin()).first;
    dp2Ans[ver].first = (*s.begin()).second;
    set<pair<int, int> >::iterator qq = s.begin();
    qq++;
    dp2[ver] += (qq->first);
    dp2Ans[ver].second = (qq->second);
  }
  for (int i = 0; i < g[ver].size(); i++) {
    int to = g[ver][i];
    if (to != p) {
      dfs(to, ver);
    }
  }
  for (int i = 0; i < g[ver].size(); i++) {
    int to = g[ver][i];
    if (to != p) {
      if (dp2[to] + 1 > dp2[ver]) {
        dp2[ver] = dp2[to] + 1;
        dp2Ans[ver] = dp2Ans[to];
      }
    }
  }
  if (dp2[ver] != 0 && s.size() != 1) {
    if (dp2Ans[ver].second != ver) {
      dp[ver] = dp2[ver];
      ans[ver].second = dp2Ans[ver];
      ans[ver].first = ver;
    }
  }
  for (int i = 0; i < g[ver].size(); i++) {
    int to = g[ver][i];
    if (to != p) {
      if ((g[ver].size() > 2 || (g[ver].size() > 1 && p == -1)) &&
          dp2[to] != 0 && dp[ver] < dp2[to] + max(pref[i], suf[i + 2]) + 1) {
        dp[ver] = dp2[to] + max(pref[i], suf[i + 2]) + 1;
        ans[ver].first = dp2Ans[to].first;
        ans[ver].second.first = dp2Ans[to].second;
        if (pref[i] > suf[i + 2]) {
          ans[ver].second.second = posPref[i];
        } else {
          ans[ver].second.second = posSuf[i + 2];
        }
      }
      if (dp[ver] < dp2[to] + 1 && dp2[to] > 0) {
        dp[ver] = dp2[to] + 1;
        ans[ver].first = dp2Ans[to].first;
        ans[ver].second.first = dp2Ans[to].second;
        ans[ver].second.second = ver;
      }
      if (dp[ver] < dp[to]) {
        dp[ver] = dp[to];
        ans[ver].first = ans[to].first;
        ans[ver].second = ans[to].second;
      }
    }
  }
  s.clear();
  for (int i = 0; i < g[ver].size(); i++) {
    int to = g[ver][i];
    if (to != p) {
      s.insert({deep[to], num[to]});
      if (s.size() == 4) {
        s.erase(s.begin());
      }
    }
  }
  if (s.size() == 2) {
    set<pair<int, int> >::iterator qq = s.begin();
    int sum = qq->first;
    w.first = qq->second;
    qq++;
    sum += qq->first;
    w.second.first = qq->second;
    w.second.second = ver;
    if (sum > dp[ver]) {
      dp[ver] = sum;
      ans[ver] = w;
    }
  }
  if (s.size() == 3) {
    set<pair<int, int> >::iterator qq = s.begin();
    int sum = qq->first;
    w.first = qq->second;
    qq++;
    sum += qq->first;
    w.second.first = qq->second;
    qq++;
    w.second.second = qq->second;
    sum += qq->first;
    if (sum > dp[ver]) {
      dp[ver] = sum;
      ans[ver] = w;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> f >> f1;
    g[f].push_back(f1);
    g[f1].push_back(f);
  }
  build(1);
  dfs(1);
  cout << dp[1] << endl;
  cout << ans[1].first << " " << ans[1].second.first << " "
       << ans[1].second.second << endl;
}
