#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,t,a; cin>>N>>t>>a;
  vii A(N);
  rep(i,0,N-1){
    int X,Y; cin>>X>>Y;
    A[X-1].push_back(Y-1);
    A[Y-1].push_back(X-1);
    }
  vi T(N,-1),A(N,-1);
  queue<int> Q;
  Q.push(t-1);
  Q.push(-1);
  int count=0;
  while(Q.size()>1){
    int K=Q.front();
    Q.pop();
    if(K==-1){
      count++;
      Q.push(-1);
      }
    else{
      T[K]=count;
      rep(i,0,A[K].size()){
        if(A[K][i]==-1)
          Q.push(A[K][i]);
        }
      }
    }
  count=0;
  Q.pop();
  Q.push(a-1);
  Q.push(-1);
  while(Q.size()>1){
    int K=Q.front();
    Q.pop();
    if(K==-1){
      count++;
      Q.push(-1);
      }
    else{
      A[K]=count;
      rep(i,0,A[K].size()){
        if(A[K][i]==-1)
          Q.push(A[K][i]);
        }
      }
    }
  int ans=0;
  rep(i,0,N){
    if(T[i]>=A[i])
      ans=max(ans,A[i]-1);
    }
  cout<<ans<<endl;
  }
