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

const int N = 1e5 + 100, inF = N;

int n, U, V, dis[2][N];
vector<int> nei[N];
queue<int> q;

void act(int v, int *dis) {
	for (int u: nei[v])
		if (dis[u] == inF) {
			dis[u] = dis[v] + 1;
			q.push(u);
		}
}

void BFS(int v, int *dis) {
	fill(dis, dis + N, inF);
	dis[v] = 0;
	q.push(v);
	while (q.size()) {
		act(q.front(), dis);
		q.pop();
	}
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> U >> V;
	U--, V--;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		nei[--u].push_back(--v);
		nei[v].push_back(u);
	}
	BFS(U, dis[0]);
	BFS(V, dis[1]);
	int ans = 0;
	for (int i = 0; i < n; i++)
		if (dis[0][i] < dis[1][i])
			ans = max(ans, dis[1][i]);
	cout << ans - 1;
}
