#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int disx[100005]={0},disy[100005]={0},vis[100005]={0};
vector<int> a[100005];
void dfs(int i,int d,int *dis)
{
	vis[i]=1;
	for(int x:a[i])
		if(vis[x]==0)
		{
			dis[x]=d;
			dfs(x,d+1,dis);
		}
}
int main(){
	int i,n,p,q;
	cin>>n>>p>>q;
	for(i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	disx[p]=0;
	dfs(p,1,disx);
	disy[q]=0;
	memset(vis,0,sizeof(vis));
	dfs(q,1,disy);
	int ans=0;
	/*for(i=1;i<=n;i++)
		cout<<disx[i]<<" ";
	cout<<endl;
	
	for(i=1;i<=n;i++)
		cout<<disy[i]<<" ";
	cout<<endl;*/
	for(i=1;i<=n;i++)
		if(disy[i]>disx[i])
			ans=max(disy[i],ans);
	cout<<ans-1<<endl;
}
