#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<int, int>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int N, u, v;
vector<vector<int>> edges;

vector<lpair> bfs(int start) {
	vector<lpair> ret(N, lpair(inf<int>, inf<int>));
	ret[start - 1] = lpair(0, start);
	queue<int> que;
	que.push(start);
	while (que.size()) {
		int now = que.front();
		que.pop();

		for (auto &edge: edges[now]) {
			if (ret[edge - 1].first > ret[now - 1].first + 1) {
				ret[edge - 1] = lpair(ret[now - 1].first + 1, edge);
				que.push(edge);
			}
		}
	}

	return ret;
}

int bfs2(int start, vector<int> &bad) {
	int ret = 0;

	vector<lpair> dis(N, lpair(inf<int>, inf<int>));
	dis[start - 1] = lpair(0, start);
	queue<int> que;
	que.push(start);
	while (que.size()) {
		int now = que.front();
		que.pop();
		ret = dis[now - 1].first;
		if (bad[now - 1] == 2) continue;

		for (auto &edge: edges[now]) {
			if (bad[edge - 1] == 1) continue;
			if (dis[edge - 1].first > dis[now - 1].first + 1) {
				dis[edge - 1] = lpair(dis[now - 1].first + 1, edge);
				que.push(edge);
			}
		}
	}

	return ret;
}

int main() {
	cin >> N >> u >> v;
	edges.resize(N + 1);
	int to, from;
	for (int i = 0; i < N - 1; ++i) {
		cin >> to >> from;
		edges[to].push_back(from);
		edges[from].push_back(to);
	}

	auto tkhs = bfs(u);
	auto aok = bfs(v);
	vector<lpair> dis(N);
	for (int i = 0; i < N; ++i) {
		dis[i] = lpair(aok[i].first - tkhs[i].first, i + 1);
	}
	sort(ALL(dis));

	int ret = 0;
	vector<int> bad(N);
	for (int i = 0; i < N; ++i) {
		if (dis[i].first < 0) {
			bad[dis[i].second - 1] = 1;
		}
		else if (dis[i].first == 0) {
			bad[dis[i].second - 1] = 2;
		}
		else {
			int last = (--upper_bound(ALL(dis), lpair(dis[i].first, inf<int>))) - dis.begin();
			for (int j = i; j <= last; ++j) {
				ret = max(ret, (dis[j].first - 1)/2*2 + bfs2(dis[j].second, bad));
			}
			for (int j = i; j <= last; ++j) {
				bad[dis[j].second - 1] = 2;
			}
			int j = i - 1;
			while (bad[dis[j].second - 1] == 2) {
				bad[dis[j--].second - 1] = 1;
			}
		}
	}

	cout << ret << endl;


	return 0;
}


/*

高橋：青木に追いつかれない範囲で遠くまで移動する
青木：高橋に向かうだけ

*/