#include "bits/stdc++.h"
using namespace std;

const int N=1e5+20;

int n,u,v,a,b,dp[2][N],ans;
vector <int> adj[N];
bool vis[2][N];

void dfs(int node,int parent,int idx,int depth=0)
{
	dp[idx][node]=depth;
	for(auto child:adj[node])
		if(child!=parent)
			dfs(child,node,idx,depth+1);
}

int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(int i=0;i<n-1;i++)
	{
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(a,0,0),dfs(b,0,1);
	for(int i=1;i<=n;i++)
		if(dp[0][i]<=dp[1][i])
			ans=max(ans,dp[1][i]-1);
	printf("%d",ans);
}