#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<int> bad(N + 1, 0);
	vector<int> far_posies;
	int maxi_dis = 0;
	for (int i = 0; i < N; ++i) {
		if (tkhs[i].first < aok[i].first) {
			if (tkhs[i].first == maxi_dis) {
				far_posies.push_back(i + 1);
			}
			else if (tkhs[i].first > maxi_dis) {
				maxi_dis = tkhs[i].first;
				far_posies.clear();
				far_posies.push_back(i + 1);
			}
		}
	}
	cerr << maxi_dis << endl;
	for (int i = 0; i < N; ++i) {
		if (aok[i].first <= maxi_dis) {
			++bad[i];
		}
		if (aok[i].first == maxi_dis+1) {
			bad[i] += 2;
		}
	}

	int ans = maxi_dis;
	int res = 0;
	for (auto pos: far_posies) {
		res = max(res, bfs2(pos, bad));
	}
	cout << ans + res << endl;


	return 0;
}


/*

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

*/