#include <bits/stdc++.h>
using namespace std;
long long n, a, t, target, bestdist = -1, dista[100002], distt[100002];
vector<long long> adjl[100002];
bool visit[100002];
int main() {
  cin >> n >> t >> a;
  for (int i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    adjl[u].push_back(v);
    adjl[v].push_back(u);
  }
  if (adjl[t].size() == 1 && adjl[a].size() == 1 && adjl[t][0] == adjl[a][0]) {
    cout << 1 << "\n";
    return 0;
  }
  memset(visit, 0, sizeof visit);
  queue<pair<pair<long long, long long>, long long> > bfs1;
  bfs1.push({{a, 0}, 0});
  while (!bfs1.empty()) {
    long long now = bfs1.front().first.first;
    long long bef = bfs1.front().first.second;
    long long distnow = bfs1.front().second;
    bfs1.pop();
    dista[now] = distnow;
    for (long long next : adjl[now]) {
      if (next == bef) continue;
      bfs1.push({{next, now}, distnow + 1});
    }
  }
  bfs1.push({{t, 0}, 0});
  while (!bfs1.empty()) {
    long long now = bfs1.front().first.first;
    long long bef = bfs1.front().first.second;
    long long distnow = bfs1.front().second;
    bfs1.pop();
    distt[now] = distnow;
    for (long long next : adjl[now]) {
      if (next == bef) continue;
      bfs1.push({{next, now}, distnow + 1});
    }
  }
  queue<pair<long long, bool> > bfs2;
  bfs2.push({t, 0});
  bfs2.push({a, 1});
  while (!bfs2.empty()) {
    long long now = bfs2.front().first;
    long long whose = bfs2.front().second;
    bfs2.pop();
    if (visit[now]) continue;
    visit[now] = 1;
    if (whose == 0 && dista[now] > bestdist) {
      bestdist = dista[now];
      target = now;
    }
    for (long long next : adjl[now]) {
      bfs2.push({next, whose});
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << dista[i] << " " << distt[i] << "\n";
  }
  cout << (abs(distt[target] - dista[target]) % 2 ? dista[target] - 1
                                                  : dista[target])
       << "\n";
}
