#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

vector<int> G[100010];
int UD[100010], VD[100010];

void dfs(int c, int p, int d, bool u) {
	if (u)UD[c] = d;
	else VD[c] = d;
	for (int i : G[c]) {
		if (i == p)continue;
		dfs(i, c, d + 1, u);
	}
}

int main() {
	int N, u, v, a, b;
	cin >> N >> u >> v;

	for (int i = 1;i < N;i++) {
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(u, 0, 0, 1);
	dfs(v, 0, 0, 0);

	int mx = 0, cost;

	for (int i = 1;i <= N;i++) {
		if (VD[i] >= UD[i]) {
			mx = max(VD[i] - 1, mx);
		}
	}
	cout << mx << endl;
}