#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
vector<int> adj[MAXN];
int n, a, t;

vector<int> bfs(int s){
	vector<int> d(n + 1, 1e9 + 1);
	d[s] = 0;
	queue<int> q;
	q.push(s);
	while (q.size()){
		int u = q.front();
		q.pop();
		for (int v : adj[u]){
			if (d[v] > 1e9){
				d[v] = d[u] + 1;
				q.push(v);
			}
		}
	}
	return d;
}

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	cin >> n >> t >> a;
	for (int i = 0; i < n - 1; ++i){
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vector<int> da = bfs(a);
	vector<int> dt = bfs(t);
	int ans = 0, prev = n + 1;
	for (int i = 1; i <= n; ++i){
		if (dt[i] < da[i]) ans = max(ans, da[i]);
	}
	cout << ans - 1;
	return 0;
}

