#include<bits/stdc++.h>
 
using namespace std;

int main(){
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> e(n + 1);
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  vector<int> dx(n + 1), dy(n + 1);
  function<void(int, int, int, vector<int>&)> dfs = [&](int cur, int par, int i, vector<int>& d) {
    for (int nex: e[cur]) {
      if (nex == par) continue;
      dfs(nex, cur, i + 1);
    }
    d[cur] = i;
  };
  dfs(x, -1, 0, dx);
  dfs(y, -1, 0, dy);
  int res = 0;
  for(int i = 1; i <= n; i++){
    if(dy[i] < dx[i]) continue;
    res=max(res, dy[i]);
  }
  cout << (res - 1) << "\n";
  return 0;
}
