#include <bits/stdc++.h>
using namespace std;
void bfs(int n, vector<stack<int>> edge, int p, vector<int> &cnt) {
  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();
    bfs(n, edge, nxt, cnt);
  }
}
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> cntA(n, -1), cntT(n, -1);
    cntA[pa - 1] = 0;
    cntT[pt - 1] = 0;
    bfs(n, edge, pt - 1, cntA);
    bfs(n, edge, pa - 1, cntT);
    int max = 0;
    for (int i = 0; i < n; i++)
      if (cntA[i] > cntT[i] && cntA[i] > max) max = cntA[i];
    cout << max << endl;
  }
}
