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


vector<int> vis;

vector<vector<int> > g;

void dfs(int node,int curr,vector<int> &h)
{
	h[node]=curr;
	vis[node]=1;
	for(auto v:g[node])
	{
		if(!vis[v])
			dfs(v,curr+1,h);
	}
}


int main()
{
	ios_base::sync_with_stdio(false);
	
	int n,a,b;
	cin>>n>>a>>b;
	
	vis.resize(n+1);
	g.resize(n+1);
	
	for(int i=0;i<n-1;i++)
	{
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	vector<int> da(n+1,0);
	vector<int> db(n+1,0);
	
	dfs(a,0,da);
	fill(vis.begin(),vis.end(),0);
	dfs(b,0,db);
	
	int ans=0;
	
	for(int i=0;i<n+1;i++)
	{
		if(da[i]<db[i])
			ans = max(ans,db[i]);
	}
	cout<<ans-1;
	
}