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

long long N, U, V, ANS = 0;
vector<vector<long long> > G;
vector<long long> DistU, DistV;

void DFS(long long P, long long Q, vector<long long>& V) {
	for (long long NP : G[P]) {
		if (NP != Q) {
			V[NP] = V[P] + 1;
			DFS(NP, P, V);
		}
	}
}

int main() {
	cin >> N >> U >> V;
	U--, V--;
	G.resize(N);
	DistU.resize(N), DistV.resize(N);
	for (int i = 0; i < N - 1; i++) {
		long long A, B;
		cin >> A >> B;
		A--, B--;
		G[A].push_back(B);
		G[B].push_back(A);
	}
	DistU[U] = 0, DistV[V] = 0;
	DFS(U, -1, DistU), DFS(V, -1, DistV);
	for (int i = 0; i < N; i++) {
		if (DistU[i] < DistV[i]) {
			ANS = max(ANS, DistV[i] - 1);
		}
	}
	cout << ANS << endl;
}