#include <bits/stdc++.h>

using namespace std;

int n, u, v, a, b, disu[100005], disv[100005], ans;
vector <int> G[100005];
queue <int> q;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> u >> v;
	for (int i=1; i<n; i++) {
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	q.push(u);
	while (!q.empty()) {
		int k = q.front();
		q.pop();
		for (int m : G[k]) {
			if (disu[m]) continue;
			disu[m] = disu[k] + 1;
			q.push(m);
		}
	}
	disu[u] = 0;
	q.push(v);
	while (!q.empty()) {
		int k = q.front();
		q.pop();
		for (int m : G[k]) {
			if (disv[m]) continue;
			disv[m] = disv[k] + 1;
			q.push(m);
		}
	}
	disv[v] = 0;
	for (int i=1; i<=n; i++) {
		if (disv[i] > disu[i]) ans = max(ans, disv[i]);
	}
	ans--;
	cout << ans << endl;
}