#include "bits/stdc++.h"
using namespace std;
vector<int>V[100100];
int Dist[100100][2];
void Haku(int s, int e, int d, int k) {
	Dist[s][k] = d;
	for (int u : V[s]) if (u != e) Haku(u, s, d + 1, k);
}
int main() {
	int N;
	scanf("%d", &N);
	int x, y;
	scanf("%d%d", &x, &y);
	for (int i = 2; i <= N; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		V[a].push_back(b);
		V[b].push_back(a);
	}
	Haku(x, x, 0, 0);
	Haku(y, y, 0, 1);
	int R = 0;
	for (int i = 1; i <= N; ++i) {
		if (Dist[i][1] < Dist[i][0]) continue;
		R = max(R, Dist[i][1]);
	}
	printf("%d\n", R - 1);
}
