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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	// ifstream cin("in.txt");	

	int n,u,v; cin>>n>>u>>v;

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

	// precalc distances
	int dist0[n+1] = {};
	int seen0[n+1] = {};
	stack<int> R;
	R.push(v);
	seen0[v] = 1;

	while (!R.empty())
	{
		int s = R.top(); R.pop();

		for (auto u: adj[s])
		{
			if (!seen0[u])
			{
				R.push(u);
				seen0[u] = 1;
				dist0[u] = dist0[s] + 1;
			}
		}
	}


	// simultaneous double bfs !

	queue<int> Q,P;
	int dist1[n+1] = {}, dist2[n+1] = {};
	int seen1[n+1] = {}, seen2[n+1] = {};
	int ans = 0;

	Q.push(u);
	P.push(v);
	seen1[u] = 1;
	seen2[v] = 1;

	// Q = escapist
	// P = chaser
	while (!Q.empty() and !P.empty())
	{
		int s = Q.front(); Q.pop();
		int t = P.front(); P.pop();

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

		// escapist moves first
		int flag = 0;
		for (auto u : adj[s])
		{
			if (!seen1[u] and  u!=t)
			{
				flag = 1;
				Q.push(u);
				dist1[u] = dist1[s]+1;
				seen1[u] = 1;
			}
			else if (u == t)
			{
				ans = max(ans, dist2[t]);
				// continue;
			}
		}

		for (auto u: adj[t])
		{
			if (!seen2[u])
			{
				P.push(u);
				dist2[u] = dist2[t] + 1;
				seen2[u] = 1;

				if (!flag)
				{
					// cout<<s<<" "<<t<<endl;
					int d = dist0[s] - dist2[u];
					d-= (d)%2;
					ans = max(ans,d + dist1[s]);
				}
			}
		}
	}

	cout<<ans<<endl;
}