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


vector <ll> graph[N];
ll alt1[N], alt2[N];



void dfs1(ll u, ll p){
    for(auto x1: graph[u]){
        if(x1 == p) continue;
        alt1[x1] = alt1[u] + 1;
        dfs1(x1, u);
    }
}


void dfs2(ll u, ll p){
    for(auto x1: graph[u]){
        if(x1 == p) continue;
        alt2[x1] = alt2[u] + 1;
        dfs2(x1, u);
    }
}




int main()
{
	ll n,x,y;
	cin>>n>>x>>y;
	//x-->tanshik intial position
	//y-->aloki  intial position
	for(ll i=0;i<n-1;i++)
	 { ll a,b;
	   cin>>a>>b;
	 	graph[a].push_back(b);
	 	graph[b].push_back(a);
	 }
	 
	   alt1[x] = 0;
    alt2[y] = 0;
    dfs1(x, -1);
    dfs2(y, -1);
    ll ans = 0;

    for(int i = 1; i <= n; i++){

        if(alt1[i] < alt2[i]) ans = max(ans, alt2[i] - 1);
    }

    cout << ans << endl;
 	
 }