#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n;
struct Event {
  int val;
  vector<int> v;
  Event(int _val) { val = _val; }
  void push(int w) { v.push_back(w); }
  bool operator<(const Event& e) const { return val < e.val; }
  Event& operator=(const Event& e) {
    vector<int> nv;
    nv.insert(nv.end(), e.v.begin(), e.v.end());
    val = e.val;
    v = nv;
    return *this;
  }
  Event operator+(const Event& e) const {
    Event ne = Event(val + e.val);
    ne.v.insert(ne.v.end(), v.begin(), v.end());
    ne.v.insert(ne.v.end(), e.v.begin(), e.v.end());
    return ne;
  }
};
vector<Event> s, d, t;
vector<int> adj[N];
bool cmp(pair<Event, int>& le, pair<Event, int>& re) {
  return re.first < le.first;
}
void dfs(int v, int p) {
  s[v] = Event(0);
  s[v].push(v);
  d[v] = Event(-1);
  t[v] = Event(-1);
  vector<pair<Event, int> > sv, dv, tv;
  for (int i = 0; i < adj[v].size(); i++) {
    int w = adj[v][i];
    if (w == p) continue;
    dfs(w, v);
    sv.push_back({s[w], w});
    dv.push_back({d[w], w});
    tv.push_back({t[w], w});
  }
  sort(sv.begin(), sv.end(), cmp);
  sort(dv.begin(), dv.end(), cmp);
  sort(tv.begin(), tv.end(), cmp);
  if (!sv.empty()) {
    if (d[v].val < sv[0].first.val + 1) {
      d[v] = sv[0].first;
      d[v].val++;
      d[v].push(v);
    }
    if (s[v].val < sv[0].first.val + 1) {
      s[v] = sv[0].first;
      s[v].val++;
    }
    if (sv.size() > 1) {
      Event ne = sv[0].first + sv[1].first;
      ne.val += 2;
      if (d[v] < ne) d[v] = ne;
      if (t[v] < ne) t[v] = ne;
      t[v].push(v);
    }
    if (sv.size() > 2) {
      Event ne = sv[0].first + sv[1].first + sv[2].first;
      ne.val += 3;
      if (t[v] < ne) t[v] = ne;
    }
  }
  if (!dv.empty()) {
    if (d[v].val < dv[0].first.val + 1) {
      d[v] = dv[0].first;
      d[v].val++;
    }
    if (t[v].val < dv[0].first.val + 1) {
      t[v] = dv[0].first;
      t[v].val++;
      t[v].push(v);
    }
  }
  if (!tv.empty() && t[v] < tv[0].first) {
    t[v] = tv[0].first;
  }
  if (!sv.empty() && !dv.empty()) {
    if (sv[0].second != dv[0].second) {
      Event ne = sv[0].first + dv[0].first;
      ne.val += 2;
      if (t[v] < ne) t[v] = ne;
    } else {
      if (sv.size() > 1) {
        Event ne = sv[1].first + dv[0].first;
        ne.val += 2;
        if (t[v] < ne) t[v] = ne;
      }
      if (dv.size() > 1) {
        Event ne = sv[0].first + dv[1].first;
        ne.val += 2;
        if (t[v] < ne) t[v] = ne;
      }
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    s.push_back(Event(-1));
    d.push_back(Event(-1));
    t.push_back(Event(-1));
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    adj[a - 1].push_back(b - 1);
    adj[b - 1].push_back(a - 1);
  }
  dfs(0, -1);
  Event ans = Event(-1);
  for (int v = 0; v < n; v++) {
    if (ans < t[v]) ans = t[v];
  }
  cout << ans.val << "\n";
  for (int i = 0; i < ans.v.size(); i++) cout << ans.v[i] + 1 << " ";
  return 0;
}
