#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int n) {
  long long int r;
  if (n == 0)
    return 1;
  else if (n == 1)
    return a;
  else
    r = power(a, n / 2);
  if (n % 2 == 0)
    return ((r) % 10) * ((r) % 10) % 10;
  else
    return ((((r) % 10) * ((r) % 10)) % 10 * ((a) % 10)) % 10;
}
long long int mai(long long int a, long long int b) {
  if (a > b)
    return a;
  else {
    return b;
  }
}
long long int madd(long long int a, long long int b) {
  long long int ans;
  ans = (a % 10 + b % 10) % 10;
  return ans;
}
long long int mmult(long long int a, long long int b) {
  long long int ans = 1;
  ans = ((a % 10) * (b % 10)) % 10;
  return ans;
}
long long int modinverse(long long int a) { return power(a, 10 - 2); }
vector<long long int> v[100005];
long long int visit[100005], pre[100005], post[100005], level[100005],
    parent[100005], ans[100005];
long long int countx = 0;
void dfs(long long int s) {
  visit[s] = 1;
  pre[s] = countx;
  countx++;
  for (long long int i = 0; i < v[s].size(); i++) {
    if (visit[v[s][i]] == 0) {
      parent[v[s][i]] = s;
      level[v[s][i]] = level[s] + 1;
      dfs(v[s][i]);
    }
  }
  post[s] = countx;
  countx++;
}
signed main() {
  long long int n;
  cin >> n;
  ;
  long long int ut;
  cin >> ut;
  ;
  long long int va;
  cin >> va;
  ;
  for (long long int i = 1; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(va);
  vector<long long int> leaf;
  for (long long int i = 1; i <= n; i++) {
    if (v[i].size() == 1) {
      leaf.push_back(i);
    }
  }
  for (long long int i = 0; i < leaf.size(); i++) {
    long long int x = leaf[i];
    long long int lvl = level[x];
    if (x != va) {
      ans[x] = lvl;
      while (x != 0) {
        ans[x] = max(ans[x], lvl);
        x = parent[x];
        ans[x] = max(ans[x], lvl);
        if (x == 0) {
          break;
        }
      }
    }
  }
  long long int temp = ut;
  long long int lt = ans[ut];
  long long int vv = lt;
  while (temp != 0) {
    cout << temp << endl;
    if (ans[temp] > lt) {
      if (level[ut] - level[temp] < level[ut]) {
        vv = max(vv, ans[temp]);
      }
    }
    temp = parent[temp];
  }
  cout << vv - 1 << endl;
}
