#include <bits/stdc++.h>
using namespace std;
long long n, a, b, Lvl[100005], Depth[100005], TT[100005];
vector<long long> V[100005];
long long DFS(long long x, long long lvl = 1, long long last = -1) {
  long long maxim = lvl;
  TT[x] = last;
  for (auto i : V[x]) {
    if (i == last) continue;
    maxim = max(maxim, DFS(i, lvl + 1, x));
  }
  Lvl[x] = lvl;
  Depth[x] = maxim;
  return maxim;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a >> b;
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    V[x].push_back(y);
    V[y].push_back(x);
  }
  DFS(b);
  long long root2 = Lvl[a] / 2 + 1 + Lvl[a] % 2;
  for (int i = Lvl[a]; i >= root2; i--) a = TT[a];
  cout << Depth[a] - 2;
  return 0;
}
