#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
vector<int>edge[100007];
int depth[100007],temp[100007],fa[100007];
void dfs(int u,int f){
    depth[u]=depth[f]+1;
    temp[u]=depth[f]+1;
    fa[u]=f;
    for(auto it:edge[u])
        if(it!=f){
            dfs(it,u);
            temp[u]=max(temp[u],temp[it]);
        }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int s,t;
    cin>>s>>t;
    for(int i=1;i<n;++i){
        int u,v;
        cin>>u>>v;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    dfs(t,0);
    int ans=0;
    int x=s;
    while(1){
        if(depth[s]-depth[x]>=depth[x]-depth[t])
            break;
        ans=max(ans,temp[x]-1);
        x=fa[x];
    }
    cout<<ans-1;
    return 0;
}
