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

#define N 100005

int n, p[N], d[N], dp[N];
vector <int> v[N];
int A, B;

void dfs(int k, int pa) {
	dp[k] = dp[pa] + 1;
	d[k] = 1; p[k] = pa;
	for (auto x : v[k]) {
		if (x == pa) continue;
		dfs(x, k);
		d[k] = max(d[k], 1 + d[x]);
	}
	return;
}

int main() {
	scanf("%d %d %d", &n, &A, &B);
	for (int i = 1, x, y; i < n; i ++) {
		scanf("%d %d", &x, &y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(B, 0);
	int ans = -1, dist = dp[A] - dp[B];
	bool f = dist & 1;
	dist = (dist - 1) >> 1;
	while (dist --) A = p[A];
	if (v[A].size() == 1) ans = dp[A] - 2;
	else ans = d[A] - 2 + dp[A] - 1;
	cout << ans << endl;
	return 0;
}
