#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7;
const ll inf=1e10;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}

const int sz=1e5+10;
vector<ll>gr[sz];
ll parent[sz][21];
ll depth[sz];
unordered_map<ll,ll>height[sz];
ll n,m,st,ed;

ll dfs(ll cur,ll dep,ll par){
	depth[cur]=dep;
	parent[cur][0]=par;
	ll mx=0;
	for(auto it: gr[cur]){
		if(it==par)
			continue;
		height[cur][it]=dfs(it,dep+1,cur)+1;
		mx=max(mx,height[cur][it]);
	}
	if(par!=-1)
		height[cur][par]=depth[par];
	return mx;
}
void findPar(){
	for(int j=1;j<21;j++){
		for(int i=1;i<=n;i++){
				if(parent[i][j-1]!=-1)
						parent[i][j]=parent[parent[i][j-1]][j-1];
		}
	}
}

ll par(ll a,ll h){
	for(int i=0;i<21;i++){
		if((h>>i)&1)
			a=parent[a][i];
	}
	return a;
}

ll lca(ll st,ll ed){
	ll h=depth[ed]-depth[st];
	ed=par(ed,h);
	
	if(ed==st)
		return ed;
	
	for(int i=20;i>=0;i--){
		if(parent[st][i]!=parent[ed][i]){
			st=parent[st][i];
			ed=parent[ed][i];
		}
	}
	return parent[st][0];
	
	
}

int main()
{
    fast;
    
    ll t;
    //~ cin>>t;
    t=1;
    while(t--){
        cin>>n>>st>>ed;
        if(st==ed){
			cout<<0;
			return 0;
		}
        for(int i=0;i<=n;i++){
			for(int j=0;j<21;j++){
				parent[i][j]=-1;
			}
		}
        for(int i=0;i<n-1;i++){
			ll f,s;
			cin>>f>>s;
			gr[f].pb(s);
			gr[s].pb(f);
		}
		dfs(1,1,-1);
		findPar();
		
		//~ ll q;
		//~ cin>>q;
		//~ while(q--){
			//~ ll st,ed;
			//~ cin>>st>>ed
			ll u=st,v=ed;
			if(depth[st]>depth[ed])
				swap(st,ed);
			ll LCA = lca(st,ed);
			ll pu=-1,pv=-1;
			if(LCA == v){
					pu=par(u,depth[u]-depth[LCA]-1);
					cout<<height[LCA][pu]-1;
					return 0;
			}
			ll mx=0;
			pv=par(v,depth[v]-depth[LCA]-1);
			for(auto it: gr[LCA]){
				if(it!=pv){
					mx=max(mx,height[LCA][it]);
				}
			}
			cout<<mx+depth[v]-depth[LCA]-1;
		//~ }
		
	}
    return 0;
}
