#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef long long ll;

int n,u,v;
vector<vector<int>> g;
vector<int> dist;

void dfs(int x){
  for(auto nx:g[x]){
    if(dist[nx]!=-1) continue;
    dist[nx]=dist[x]+1;
    dfs(nx);
  }
}

int main(){
  cin>>n>>u>>v;
  u--; v--;
  g.resize(n);
  dist.assign(n,-1);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--; b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  dist[v]=0;
  dfs(v);
  vector<int> dist2(n);
  rep(i,n) dist2[i]=dist[i];
  dist.assign(n,-1);
  dist[u]=0;
  dfs(u);
  
  int res=0;
  
  rep(i,n){
    if(g[i].size()==1){
      if(dist2[i]>dist[i]) res=max(res,dist2[i]);
    }
  }
  cout<<res-1<<endl;
}