#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+1;
int n,a,b,tot,ans,u,v;
int dis1[N],dis2[N],pre[N<<1],las[N],des[N<<1];
void dfs1(int x)
{
	for (int i=las[x];i;i=pre[i])
		if (!dis2[des[i]])
		{
			dis2[des[i]]=dis2[x]+1;
			dfs1(des[i]);
		}
}
void dfs2(int x)
{
	for (int i=las[x];i;i=pre[i])
		if (!dis1[des[i]]&&dis1[x]+1<dis2[des[i]])
		{
			dis1[des[i]]=dis1[x]+1;
			dfs2(des[i]);
		}
}
void link(int x,int y)
{
	pre[++tot]=las[x];
	des[tot]=y;
	las[x]=tot;
}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for (int i=1;i<n;++i)
	{
		scanf("%d%d",&u,&v);
		link(u,v);
		link(v,u);
	}
	dis2[b]=1;
	dfs1(b);
	dis1[a]=1;
	dfs2(a);
	for (int i=1;i<=n;++i)
		if (dis1[i])
			ans=max(ans,dis2[i]-2);
	printf("%d",ans);
	return 0;
}