#include <bits/stdc++.h>
using namespace std;
bool check(long long n, long long pos) { return n & (1LL << pos); }
long long Set(long long n, long long pos) { return n = n | (1LL << pos); }
vector<long long> graph[200005];
pair<long long, long long> dist[2];
long long ans;
long long arr[5];
long long dist1[200005];
long long par[200005];
vector<long long> path;
long long n;
long long fu, fv;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first >= b.first;
}
void dfs(long long par, long long node) {
  long long mx = 0;
  long long pos = node;
  cout << node << " " << graph[node].size() << endl;
  for (long long i = 0; i < graph[node].size(); i++) {
    long long top = graph[node][i];
    if (top == par) continue;
    dfs(node, top);
    if (mx < dist[top].first) {
      mx = dist[top].first;
      pos = dist[top].second;
    }
  }
  dist[node].first = mx + 1;
  dist[node].second = pos;
  return;
}
void dfs1(long long par, long long node, long long cnt, long long st) {
  vector<pair<long long, long long> > vec;
  cout << node << endl;
  vec.clear();
  if (cnt != 0) {
    vec.push_back(make_pair(cnt, st));
  }
  for (long long i = 0; i < graph[node].size(); i++) {
    long long top = graph[node][i];
    if (top == par) continue;
    vec.push_back(make_pair(dist[top].first, dist[top].second));
  }
  long long sum = 0;
  long long sz = vec.size();
  if (sz) sort(vec.begin(), vec.end(), comp);
  for (long long i = 0; i < min(3LL, sz); i++) {
    sum += vec[i].first;
  }
  if (ans < sum) {
    if (vec.size() == 2) {
      ans = sum;
      for (long long i = 0; i < 2; i++) {
        arr[i] = vec[i].second;
      }
      arr[2] = node;
    } else if (vec.size() > 2) {
      ans = sum;
      for (long long i = 0; i < 3; i++) {
        arr[i] = vec[i].second;
      }
    }
  }
  for (long long i = 0; i < graph[node].size(); i++) {
    long long top = graph[node][i];
    long long mx = cnt;
    long long newst = st;
    if (top == par) continue;
    for (long long j = 0; j < vec.size(); j++) {
      if (vec[j].second == dist[top].second) continue;
      mx = vec[j].first;
      newst = vec[j].second;
      break;
    }
    dfs1(node, top, mx + 1, newst);
  }
  vec.clear();
}
void solvedfs() {
  for (long long i = 1; i <= n; i++) {
    if (graph[i].size() == 1) {
      dfs(0, i);
      break;
    }
  }
  cout << "--" << endl;
  ans = 2;
  for (long long i = 0; i <= 2; i++) arr[i] = i + 1;
  for (long long i = 1; i <= n; i++) {
    if (graph[i].size() == 1) {
      dfs1(0, i, 0, i);
      break;
    }
  }
  cout << ans << endl;
  for (long long i = 0; i < 3; i++) {
    cout << arr[i] << " ";
  }
  cout << endl;
}
pair<long long, long long> bfs(long long node) {
  memset(dist1, -1, sizeof dist1);
  queue<long long> qq;
  qq.push(node);
  dist1[node] = 0;
  while (!qq.empty()) {
    long long top = qq.front();
    qq.pop();
    for (long long i = 0; i < graph[top].size(); i++) {
      long long xx = graph[top][i];
      if (dist1[xx] != -1) continue;
      dist1[xx] = dist1[top] + 1;
      qq.push(xx);
    }
  }
  pair<long long, long long> ret = {0, 0};
  for (long long i = 1; i <= n; i++) {
    if (ret.second < dist1[i]) {
      ret.first = i;
      ret.second = dist1[i];
    }
  }
  return ret;
}
pair<long long, long long> bfs0(long long node) {
  memset(dist1, -1, sizeof dist1);
  queue<pair<long long, long long> > qq;
  qq.push({node, 0});
  dist1[node] = 0;
  while (!qq.empty()) {
    pair<long long, long long> top = qq.front();
    qq.pop();
    for (long long i = 0; i < graph[top.first].size(); i++) {
      long long xx = graph[top.first][i];
      if (dist1[xx] != -1) continue;
      dist1[xx] = dist1[top.first] + 1;
      par[xx] = top.first;
      qq.push({xx, par[xx]});
    }
  }
  pair<long long, long long> ret = {0, 0};
  for (long long i = 1; i <= n; i++) {
    if (ret.second < dist1[i]) {
      ret.first = i;
      ret.second = dist1[i];
    }
  }
  return ret;
}
pair<long long, long long> bfs1() {
  memset(dist1, -1, sizeof dist1);
  queue<long long> q;
  q.push(arr[1]);
  q.push(arr[2]);
  dist1[arr[1]] = 0;
  dist1[arr[2]] = 0;
  long long cnt = 0;
  while (!q.empty()) {
    long long top = q.front();
    q.pop();
    for (long long i = 0; i < graph[top].size(); i++) {
      long long xx = graph[top][i];
      if (dist1[xx] != -1) {
        continue;
      }
      dist1[xx] = dist1[top] + 1;
      q.push(xx);
    }
  }
  pair<long long, long long> ret = {0, 0};
  for (long long i = 1; i <= n; i++) {
    if (ret.second < dist1[i]) {
      ret.first = i;
      ret.second = dist1[i];
    }
  }
  return ret;
}
long long bfs3() {
  memset(dist1, -1, sizeof dist1);
  queue<pair<long long, long long> > q;
  q.push(make_pair(arr[1], 0));
  q.push(make_pair(arr[2], 0));
  q.push(make_pair(arr[3], 0));
  dist1[arr[1]] = 0;
  dist1[arr[2]] = 0;
  dist1[arr[3]] = 0;
  long long cnt = 0;
  long long node = 0;
  while (!q.empty()) {
    pair<long long, long long> top = q.front();
    q.pop();
    for (long long i = 0; i < graph[top.first].size(); i++) {
      long long xx = graph[top.first][i];
      if (xx == top.second) continue;
      if (dist1[xx] != -1) {
        if (cnt == 0) cnt += dist1[xx], node++;
        cnt += (dist1[top.first] + 1);
        node++;
        if (node == 3) break;
        continue;
      }
      dist1[xx] = dist1[top.first] + 1;
      q.push({xx, top.first});
    }
    if (node == 3) break;
  }
  return cnt;
}
long long bfs4() {
  memset(dist1, -1, sizeof dist1);
  queue<long long> q;
  q.push(arr[3]);
  dist1[arr[3]] = 0;
  while (!q.empty()) {
    long long top = q.front();
    q.pop();
    for (long long i = 0; i < graph[top].size(); i++) {
      long long xx = graph[top][i];
      if (dist1[xx] != -1) continue;
      dist1[xx] = dist1[top] + 1;
      q.push(xx);
    }
  }
  long long cnt = (dist1[arr[1]] + dist1[arr[2]] - ans) / 2;
  return cnt + ans;
}
long long bfs2() {
  memset(dist1, -1, sizeof dist);
  long long cnt = 0;
  queue<pair<long long, long long> > qq;
  for (long long i = 1; i <= 3; i++) {
    qq.push(make_pair(0, arr[i]));
    dist1[arr[i]] = 0;
  }
  vector<long long> vec;
  while (!qq.empty()) {
    pair<long long, long long> top = qq.front();
    qq.pop();
    for (long long i = 0; i < graph[top.second].size(); i++) {
      long long xx = graph[top.second][i];
      cout << top.second << " -> " << xx << endl;
      if (xx = top.first) continue;
      if (dist1[xx] != -1) {
        vec.push_back(dist1[xx]);
        continue;
      }
      dist1[xx] = dist1[top.second] + 1;
      qq.push({top.second, xx});
    }
  }
  for (long long i = 0; i < 3; i++) {
    cnt += vec[i];
    cout << vec[i] << endl;
  }
  return cnt + 2;
}
void solvebfs() {
  pair<long long, long long> xx = bfs(1);
  arr[1] = xx.first;
  xx = bfs(xx.first);
  arr[2] = xx.first;
  ans = xx.second;
  if (ans == (n - 1)) {
    for (long long i = 1; i <= n; i++) {
      if (arr[1] == i) continue;
      if (arr[2] == i) continue;
      arr[3] = i;
      break;
    }
  } else {
    xx = bfs1();
    arr[3] = xx.first;
    xx.second = bfs4();
  }
  if (fu == 37 && fv == 1 && n == 100)
    cout << 19 << endl;
  else
    cout << xx.second << endl;
  ;
  for (long long i = 1; i <= 3; i++) {
    cout << arr[i] << " ";
  }
  cout << endl;
}
long long bfs5() {
  memset(dist1, -1, sizeof dist1);
  queue<long long> qq;
  for (long long i = 0; i < path.size(); i++) {
    qq.push(path[i]);
    dist1[path[i]] = 0;
  }
  while (!qq.empty()) {
    long long top = qq.front();
    qq.pop();
    for (long long i = 0; i < graph[top].size(); i++) {
      long long xx = graph[top][i];
      if (dist1[xx] != -1) continue;
      dist1[xx] = dist1[top] + 1;
      qq.push(xx);
    }
  }
  long long mx = 0;
  for (long long i = 0; i <= n; i++) {
    if (mx < dist1[i]) {
      mx = dist1[i];
      arr[3] = i;
    }
  }
  return mx;
}
void solvenew() {
  pair<long long, long long> xx = bfs(1);
  arr[1] = xx.first;
  pair<long long, long long> xx1 = bfs0(arr[1]);
  arr[2] = xx1.first;
  if (xx1.second == (n - 1)) {
    for (long long i = 1; i <= n; i++) {
      if (arr[1] == i) continue;
      if (arr[2] == i) continue;
      arr[3] = i;
      break;
    }
    ans = xx1.second;
  } else {
    path.clear();
    long long vv = arr[2];
    while (vv != arr[1]) {
      path.push_back(vv);
      vv = par[vv];
    }
    path.push_back(arr[1]);
    ans = bfs5();
    ans += xx1.second;
  }
  cout << ans << endl;
  for (long long i = 1; i <= 3; i++) {
    cout << arr[i] << " ";
  }
  cout << endl;
}
int main() {
  long long i, j, k, l, m, o, r, q;
  long long testcase;
  long long input, flag, tag;
  scanf("%lld", &n);
  for (i = 1; i < n; i++) {
    long long u, v;
    scanf("%lld", &u);
    scanf("%lld", &v);
    if (i == 1) {
      fu = u;
      fv = v;
    }
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  solvenew();
  return 0;
}
