#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int n, u, v;
vector<vector<int>> tr;

void f(vector<int>& d, int s)
{
	queue<pair<int,int>> q;
	q.push(pair<int,int>(s,0));
	d[s] = 0;
	while (!q.empty())
	{
		pair<int,int>& f = q.front();
		for (auto& i : tr[f.first]) {
			if (d[i] == -1) {
				q.push(pair<int,int>(i, f.second + 1));
				d[i] = f.second + 1;
			}
		}
		q.pop();
	}
}

int main()
{
	cin >> n >> u >> v;
	tr.resize(n + 1);

	for (int i = 1; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		tr[a].push_back(b);
		tr[b].push_back(a);
	}

	vector<int> td(n + 1, -1);
	f(td, u);
	vector<int> ad(n + 1, -1);
	f(ad, v);

	int ret = 0;
	for (int i = 1; i <= n; ++i) {
		if (td[i] < ad[i]) {
			if (ret < ad[i] - 1) {
				ret = ad[i] - 1;
			}
		}
	}

	cout << ret << endl;

	return 0;
}