#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
void solve() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<int> to[n];
  int a, b;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vector<int> distao(n);
  for (int i = 0; i < n; i++) distao[i] = -1;
  distao[v] = 0;
  queue<int> Q;
  Q.push(v);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = 0; i < to[x].size(); i++) {
      if (distao[to[x][i]] == -1) {
        Q.push(to[x][i]);
        distao[to[x][i]] = distao[x] + 1;
      }
    }
  }
  vector<P> distaka(n);
  for (int i = 0; i < n; i++) {
    distaka[i].first = -1;
    distaka[i].second = i;
  }
  distaka[u].first = 0;
  queue<int> Q1;
  Q1.push(u);
  while (!Q1.empty()) {
    int x = Q1.front();
    Q1.pop();
    for (int i = 0; i < to[x].size(); i++) {
      if (distaka[to[x][i]].first == -1) {
        Q1.push(to[x][i]);
        distaka[to[x][i]].first = distaka[x].first + 1;
      }
    }
  }
  vector<P> zdist(n);
  for (int i = 0; i < n; i++) {
    zdist[i].first = distao[i];
    zdist[i].second = distaka[i].second;
  }
  sort(zdist.rbegin(), zdist.rend());
  for (int i = 0; i < zdist.size(); i++) {
    int a = zdist[i].first, b = zdist[i].second;
    cout << a << " " << distaka[b].first << " " << distao[b] << " " << b
         << endl;
    if (a <= distaka[b].first) continue;
    cout << distao[b] - 1 << endl;
    return;
  }
  cout << 0 << endl;
}
signed main() { solve(); }
