#include <bits/stdc++.h>
using namespace std;
int bfs(int n, vector<stack<int>> &edge, int p, vector<int> &cnt) {
  int max = cnt[p];
  queue<int> q;
  while (!edge[p].empty()) {
    int nxt = edge[p].top();
    edge[p].pop();
    if (cnt[nxt] < 0) {
      cnt[nxt] = cnt[p] + 1;
      q.push(nxt);
    }
  }
  while (!q.empty()) {
    int nxt = q.front();
    q.pop();
    int tmp = bfs(n, edge, nxt, cnt);
    if (max < tmp) max = tmp;
  }
  return max;
}
int main() {
  int n, pa, pt;
  while (cin >> n && n) {
    cin >> pa >> pt;
    vector<stack<int>> edge(n);
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      cin >> a >> b;
      edge[a - 1].push(b - 1);
      edge[b - 1].push(a - 1);
    }
    if (edge[pt - 1].size() == 1 && edge[pt - 1].top() == pa - 1) {
      cout << 0 << endl;
      break;
    }
    vector<int> cnt(n, -1);
    cnt[pa - 1] = 0;
    cout << bfs(n, edge, pt - 1, cnt) << endl;
  }
}
