#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int n = 100005,u,v;
vector<int> dis_u(n);
vector<int> dis_v(n);
vector<vector<int>> tree(n,vector<int>());

void dfs(int i,int before,int d,int par){
  if(par == u) dis_u.at(i) = d;
  else dis_v.at(i) = d;
  
  for(int p:tree.at(i)){
    if(p == before) continue;
    dfs(p,i,d+1,par);
  }
}
  
 
int main() {
  cin >> n >> u >> v;
  --u;--v;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a;--b;
    tree.at(a).push_back(b);
    tree.at(b).push_back(a);
  }
  
  dfs(u,-1,0,u);
  dfs(v,-1,0,v);
  
  int ans = 0;
  rep(i,n){
    if(dis_u.at(i) < dis_v.at(i)){
      ans = max(ans,dis_v.at(i)-1);
    }
  }
  cout << ans << endl;
  
  return 0;
}



