#include <bits/stdc++.h>
using namespace std;
int n, a, b;
vector<int> G[111111];
int distA[111111];
int distB[111111];
void dfsA(int now, int cnt) {
  distA[now] = cnt;
  for (int i = 0; i < G[now].size(); i++) {
    if (distA[G[now][i]] != -1) continue;
    dfsA(G[now][i], cnt + 1);
  }
}
void dfsB(int now, int cnt) {
  distB[now] = cnt;
  for (int i = 0; i < G[now].size(); i++) {
    if (distB[G[now][i]] != -1) continue;
    dfsB(G[now][i], cnt + 1);
  }
}
int main() {
  cin >> n >> a >> b;
  a--;
  b--;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (int i = 0; i < n; i++) distA[i] = -1;
  for (int i = 0; i < n; i++) distB[i] = -1;
  dfsA(a, 0);
  dfsB(b, 0);
  int ans = -1;
  for (int i = 0; i < n; i++) {
    if (distA[i] < distB[i]) ans = max(ans, distA[i]);
  }
  cout << ans << endl;
  return 0;
}
