#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,u,v;
int dist1[maxn],dist2[maxn];
vector<int> graph[maxn];
void dfs1(int x,int par)
{
	for(int i=0;i<graph[x].size();i++)
	{
		int to=graph[x][i];
		if(to==par)
			continue;
		dist1[to]=dist1[x]+1;
		dfs1(to,x);
	}
}
void dfs2(int x,int par)
{
	for(int i=0;i<graph[x].size();i++)
	{
		int to=graph[x][i];
		if(to==par)
			continue;
		dist2[to]=dist2[x]+1;
		dfs2(to,x);
	}
}
int main()
{
	cin>>n>>u>>v;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	dfs1(u,-1);
	dfs2(v,-1);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(dist1[i]<dist2[i])
		{
			ans=max(ans,dist2[i]-1);
		}
	}
	cout<<ans<<endl;
	return 0;
}