#include<bits/stdc++.h>
using namespace std;
const int mxn=1e5+5;

vector<int>g[mxn];

void dfs(int r, int p, vector<int>&dist, int cnt){
     dist[r]=cnt;
     for(int i=0;i<g[r].size();i++){
          int ch=g[r][i];
          if(ch==p)continue;
          dfs(ch, r, dist, cnt+1);
     }
}

int main(){
     int n, u, v; cin>>n>>u>>v;

     for(int i=0;i<n-1;i++){
          int a, b; cin>>a>>b;
          g[a].push_back(b);
          g[b].push_back(a);
     }

     vector<int>dist1(mxn), dist2(mxn);

     dfs(u, -1, dist1, 0);
     dfs(v, -1, dist2, 0);

     int ans=0;
     for(int i=1;i<=n;i++){
          if(dist1[i]<dist2[i])ans=max(ans, dist2[i]);
     }
     cout<<ans-1;
}