#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

void dfs(vector<vector<ll>> &tree, ll now, ll bf, vector<ll> &ans, ll o, vector<ll> &leaf, bool mode){
	bool flag = true;
	for(ll i : tree.at(now)){
		if(i == bf) continue;
		ans.at(i) = ans.at(now) + 1;
		flag = false;
		if(i == o){
			leaf.push_back(i);
			continue;
		}
		dfs(tree, i, now, ans, o, leaf, mode);
	}
	if(mode == true && flag == true) leaf.push_back(now);
}

ll main(){
	ll n, u, v;
	cin >> n >> u >> v;
	u--; v--;
	vector<vector<ll>> tree(n, vector<ll>());
	rep(i, n-1){
		ll a, b;
		cin >> a >> b;
		a--; b--;
		tree.at(a).push_back(b);
		tree.at(b).push_back(a);
	}
	//cerr << "tst" << endl;
	vector<ll> u_d(n, 1001001), v_d(n, 1001001), leaf;
	u_d.at(u) = 0;
	dfs(tree, u, -1, u_d, v, leaf, false);
	v_d.at(v) = 0;
	dfs(tree, v, -1, v_d, u, leaf, true);
	ll ans = 0;
	for(ll i : leaf){
		// cerr << i << ":" << u_d.at(i) << " " << v_d.at(i) << endl;
		if(u_d.at(i) < v_d.at(i)){
			ans = max(ans, v_d.at(i));
		}
	}
	ans--;
	cout << ans << endl;
	
	return 0;
}