#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
struct bian{int nxt,to;}bi[200020];
int n,s,t,dis1[100010],dis2[100010],head[100010],num,ans;
inline void add(int from,int to){bi[++num]=bian{head[from],to};head[from]=num;}
void bfs(int v,int dis[])
{
	dis[v]=1;queue<int>q;
	q.push(v);
	int x,y;
	while(!q.empty())
	{
		x=q.front();q.pop();
		for(int i=head[x];i;i=bi[i].nxt)
		{
			y=bi[i].to;
			if(!dis[y])dis[y]=dis[x]+1,q.push(y);
		}
	}
}
int main()
{
	scanf("%d %d %d",&n,&s,&t);
	int x,y;
	for(int i=1;i<n;++i)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x);
	}
	bfs(s,dis1);
	bfs(t,dis2);
	for(int i=1;i<=n;++i)
		if(dis1[i]<dis2[i])ans=max(ans,dis2[i]-2);
	printf("%d",ans);
	return 0;
}
