#include<bits/stdc++.h>
using namespace std;
vector<int>G[100005];
int u,v,n;
vector<int> Takahashi(100005,100005);
vector<int> Aoki(100005,100005);
void dfs1(int curr,int last,int step){
  Aoki[curr] = step;
  for(auto i:G[curr]){
    if(i!=last){
      dfs1(i,curr,step+1);
    }
  }
}
void dfs2(int curr,int last,int step){
  if(curr == v){
    return ;
  }
  Takahashi[curr] = step;
  for(auto i:G[curr]){
    if(i!=last){
      dfs2(i,curr,step+1);
    }
  }  
}
int main(){
  cin>>n>>u>>v;
  for(int i=0;i<n-1;++i){
    int f,t;cin>>f>>t;
    G[f].push_back(t);
    G[t].push_back(f);
  }
  if(u==v){cout<<0<<endl;return 0;}
  dfs1(v,-1,0);
  dfs2(u,-1,0);
  int res = 0;
  for(int i=1;i<=n;++i){
    if(Aoki[i] > Takahashi[i]){
      res = max(res,Aoki[i]-1);
    }
  }
  cout<<res<<endl;
  return 0;
}
