#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 
ll sx,sy;

ll dp[100005],vis1[100005],vis[100005],par[100005];
vector<ll>ad[100005];
vector<ll>path;

ll dfs(ll idx)
{

	ll mx=0;
	vis1[idx]=1;
	for(ll i=0;i<sz(ad[idx]);i++)
	{
		ll x=ad[idx][i];
		if(!vis1[x])
			mx=max(mx,dfs(x));
	}
	dp[idx]=mx;
	return 1+mx;
}

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m,a,b;

	cin >> n >> sy >> sx;

	for(i=1;i<=n-1;i++)
	{
		cin >> x >> y;
		ad[x].pb(y);
		ad[y].pb(x);
	}

	queue<ll>q;
	q.push(sx);
	vis[sx]=1;
	ll f=0;
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		for(i=0;i<sz(ad[x]);i++)
		{
			y=ad[x][i];
			if(!vis[y])
			{
				vis[y]=1;
				q.push(y);
				par[y]=x;
				if(y==sy)
				{
					f=1;
					break;
				}
			}
		}
		if(f)
			break;
	}
	path.pb(sy);
	x=par[sy];
	while(x!=sx)
	{
		path.pb(x);
		x=par[x];
	}
	path.pb(sx);
	reverse(all(path));

	dfs(sx);

	ll sr=sz(path)/2;
	if(sz(path)%2==1)
		sr++;
	ll ans=sz(path)-1-sz(path)/2;
	for(i=sr;i<sz(path);i++)
	{
		x=sz(path)-1-i;
		ans=max(ans,dp[path[i]]+x);
	}

	cout<<ans<<endl;
}