#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int n, x, a, b, ans;
vector<int> g[N];
int dist1[N], dist2[N];

void dfs(int u, int par, int dist[])
{
	dist[u]= dist[par] + 1;
	for(auto &it:g[u])
	{
		if(it == par)
			continue;
		dfs(it, u, dist);
	}
}

int32_t main()
{
	IOS;
	cin >> n >> a >> b;
	for(int i = 1; i <= n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dist1[0] = -1;
	dist2[0] = -1;
	dfs(a, 0, dist1);
	dfs(b, 0, dist2);
	for(int i = 1; i <= n; ++i)
	{
		if(dist1[i] < dist2[i])
		{
			int cur = dist2[i];
			ans = max(ans, cur - 1);
		}
	}
	cout << ans;
}