#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)


// Write From This Line
vector<int> to[100005];

int n;
vector<int> dist(n);
void dfs(int s, int d=0, int p = -1){
	dist[s] = d;
	for(int u:to[s]){
		if(u == p) continue;
		dfs(u,d+1,s);
	}
}
vector<int> calcDist(int s) {
	// sからの各頂点への距離を求める
	dist = vector<int> (n);
	dfs(s);
	return dist;
}
int main()
{
	int s, t;
	cin >> n >> s >> t;
	--s, --t;
	rep(i,n-1){
		int a, b;
		cin >> a >> b;
		--a, --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	vector<int> distS = calcDist(s);
	vector<int> distT = calcDist(t);

	int mx = 0;
	rep(i,n){
		if(distS[i] < distT[i]){
			mx = max(mx,distT[i]);
		}
	}
	int ans = mx - 1;
	cout << ans << endl;
}
