#include<bits/stdc++.h>
using namespace std;
const int N=100005;
vector<int>e[N];
int dep[N],md[N],fa[N],n,s,t;
void dfs(int u,int f)
{
	dep[u]=md[u]=dep[f]+1,fa[u]=f;
	for(auto v:e[u])
		if(v!=f)
			dfs(v,u),md[u]=max(md[u],md[v]);
}
int main()
{
	scanf("%d%d%d",&n,&s,&t);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(t,0);
	int ans=0,x=s;
	while(1)
	{
		if(dep[s]-dep[x]>=dep[x]-dep[t])
			break;
		ans=max(ans,md[x]-1);
		x=fa[x];
	}
	printf("%d\n",ans-1);
	return 0;
}
