#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void dfs(vector<vector<int>>& Tree, vector<int>& Dists, int now, int before) {
	for (int u : Tree[now]) {
		if (u == before) continue;
		Dists[u] = Dists[now] + 1;
		dfs(Tree, Dists, u, now);
	}
}

int main() {
	int N, u, v;
	cin >> N >> u >> v;
	u--, v--;
	vector<vector<int>> Tree(N);
	for (int i = 0; i < N - 1; i++) {
		int A, B;
		cin >> A >> B;
		Tree[A - 1].push_back(B - 1);
		Tree[B - 1].push_back(A - 1);
	}
	vector<int> DistT(N), DistA(N);
	dfs(Tree, DistT, u, -1);
	dfs(Tree, DistA, v, -1);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (DistT[i] > DistA[i]) continue;
		ans = max(ans, DistA[i] - 1);
	}
	cout << ans << endl;
}
