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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;

vector<int> adj[maxr];
int level[maxr];
void dfs(int root, int parent, int lvl) {
	level[root] = lvl;
	for (auto x : adj[root]) {
		if (x == parent)
			continue;
		dfs(x, root, lvl + 1);
	}
}
int ans = 0;
void dfs_t(int root, int parent, int dis) {
	if (level[root] <= dis)
		return ;
	for (auto x : adj[root]) {
		if (x == parent)
			continue;
		dfs_t(x, root, dis + 1);
	}
	ans = max(ans, level[root] - 1);
}

int32_t main()
{
	GO;
	int n, u, v;
	cin >> n >> u >> v;
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(v, -1, 0);

	dfs_t(u, -1, 0);
	cout << ans << endl;
	return 0;
}

//!