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

#define eb emplace_back
#define sz(s) (int)(s.size())

const int N = 2e6 + 123;

int dist[N];

vector <int> g[N];

int res = 0;

void dfs(int v, int pr = -1) {
	for (auto to : g[v]) {
		if (to != pr) {
			dist[to] = dist[v] + 1;
			dfs(to, v);
		}
	}
}

void dfs2(int v, int pr, int d) {
	if (d >= dist[v])
		return;
	res = max(res, dist[v] - 1);
	for (auto to : g[v])
		if (to != pr)
			dfs2(to, v, d + 1);
}

int main () {
	cerr << "Ready\n";
	int n, s, f;
	cin >> n >> s >> f;
	for (int i = 1; i < n; ++ i) {
		int x, y;
		cin >> x >> y;
		g[x].eb(y);
		g[y].eb(x);
	}
	dfs(f);
	dfs2(s, -1, 0);
	cout << res;
	cerr << '\n';
}