#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll d[100005],par[100005];
vector<vector<ll>> v(100005);
ll dfs(ll i,ll p){
    par[i]=p;
    for(ll j=0;j<v[i].size();j++)
    if(v[i][j]!=p)
    d[i]=max(d[i],dfs(v[i][j],i));
    return d[i]+1;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,a,b;
    cin>>n>>b>>a;
    if(a==b){
        cout<<0;
        exit(0);
    }
    for(ll i=0;i<n-1;i++){
        ll x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(a,a);
    ll val=1,p=b;
    while(par[p]!=p){
        p=par[p];
        val++;
    }
    ll sum=ceil(val/2.0)-1,q=val/2-1;
    p=b;
    val=0;
    while(val<q){
        p=par[p];
        val++;
    }
    cout<<(sum+d[p])<<endl;
}