#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

#define NDEBUG

int main() {
	int n, u, v; scanf("%d%d%d", &n, &u, &v); u--; v--;
	std::vector<std::vector<int>> g(n);
	std::vector<int> a(n - 1), b(n - 1);
	for(int i = 0; i < n - 1; i++) {
		scanf("%d%d", &a[i], &b[i]);
		a[i]--; b[i]--;

		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}

	std::vector<int> dist(n, -1);
	std::queue<int> qu({v}); dist[v] = 0;
	while(!qu.empty()) {
		auto v = qu.front(); qu.pop();

		for(auto e: g[v]) {
			if(dist[e] != -1) continue;
			dist[e] = dist[v] + 1;
			qu.push(e);
		}
	}
	
	std::vector<int> kiri(n);
	auto dfs = [&](auto && dfs, int v, int par) -> void {
		for(auto e: g[v]) {
			if(e == par) continue;
			dfs(dfs, e, v);
			kiri[v] = std::max(kiri[v], kiri[e] + 1);
		}
	};
	dfs(dfs, v, -1);

	#ifndef NDEBUG
	for(auto v: dist) cout << v << " "; cout << endl;
	for(auto v: kiri) cout << v << " "; cout << endl;
	#endif

	int ans = kiri[u];
	auto solve = [&](auto&& solve, int v, int par, int d) -> void {
		if(dist[v] > d) {
			ans = std::max(ans, d + kiri[v]);
		} else if(dist[v] == d) {
			ans = std::max(ans, d);
			return;
		}
		
		for(auto e: g[v]) {
			if(e == par) continue;
			solve(solve, e, v, d + 1);
		}
	};
	solve(solve, u, -1, 0);
	
	printf("%d\n", ans);
	return 0;
}
