#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 2e5 + 7;
const int maxm = 1e6 + 7;
const int ALP = 26;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;

int n;
int u,v;
int dis_to_u[maxn],dis_to_v[maxn];
vector<int> pic[maxn];
int f[maxn];

void dfs(int cur,int fa)
{
	f[cur]=fa;
	for(int i:pic[cur])
	{
		if(i==fa)
			continue;
		dfs(i,cur);
	}
}

void dfs_u(int cur,int fa,int dis)
{
	dis_to_u[cur]=dis;
	for(int nxt:pic[cur])
	{
		if(nxt==fa)
			continue;
		dfs_u(nxt,cur,dis+1);
	}
}

void dfs_v(int cur,int fa,int dis)
{
	dis_to_v[cur]=dis;
	for(int nxt:pic[cur])
	{
		if(nxt==fa)
			continue;
		dfs_v(nxt,cur,dis+1);
	}
}

int ans;

int main()
{
	scanf("%d%d%d",&n,&u,&v);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		pic[u].push_back(v);
		pic[v].push_back(u);
	}
	dfs(v,0);
	dfs_u(u,0,0);
	dfs_v(v,0,0);
	
	for(int i=1;i<=n;i++)
	{
		if(dis_to_u[i]>dis_to_v[i])
			continue;
		ans=max(ans,dis_to_v[f[i]]);
	}
	printf("%d\n",ans);
	return 0;
}
