#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;

vector<vector<int>> tree;
void dfs(int now,int d,vector<int> &dist){
    for(auto v:tree[now]){
        if(dist[v]>=0) continue;
        dist[v]=dist[now]+1;
        dfs(v,d+1,dist);
    }
}

int main(){
    int N,u,v;
    cin>>N>>u>>v;
    u--;v--;
    tree.resize(N);
    REP(i,N-1){
        int a,b; cin>>a>>b;
        a--;b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<int> du(N,-1),dv(N,-1);
    du[u]=0;dv[v]=0;
    dfs(u,0,du);
    dfs(v,0,dv);
    int ans=0;
    REP(i,N){
        if(du[i]<dv[i]){
            ans=max(ans,dv[i]-1);
        }
    }
    cout<<ans<<endl;
}
