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

int main()
{
	//ifstream cin("in.txt");

	int n,u,v; cin>>n>>u>>v;
	vector<int> adj[n+1];

	for (int i = 1; i<n; i++)
	{
		int a,b; cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}


	stack<int> Q,P;
	int ans = 0;
	int dist1[n+1] = {}, dist2[n+1] = {};
	int seen1[n+1] = {}, seen2[n+1] = {};
	Q.push(u); P.push(v);
	seen1[u]=1; seen2[v]=1;

	while (!Q.empty() and !P.empty())
	{
		int s = Q.top(), t = P.top();
		Q.pop(); P.pop();

		if (s==t)
		{
			ans = max(ans,dist1[s]);
			continue;
		}

		for (int i = 0, l = adj[t].size(); i<l; i++)
		{
			int u = adj[t][i];
			if (!seen2[u] and u!=s)
			{
				P.push(u);
				dist2[u] = dist2[t]+1;
				seen2[u] = 1;
			}
		}

		for (int i = 0, l = adj[s].size(); i<l; i++)
		{
			int u = adj[s][i];
			if (!seen1[u])
			{
				Q.push(u);
				dist1[u] = dist1[s]+1;
				seen1[u] = 1;
			}
		}
	}

	cout<<ans<<endl;
}