#include<bits/stdc++.h>
using namespace std;

long long n, t, a, maxd[100002], par[100002], dist, ans=0;
vector<long long>adjl[100002];

long long dfs1(long long now, long long bef, long long distnow){
	par[now]=bef;
	if (now==t) dist=distnow;
	if (adjl[now].size()==1 && adjl[now][0]==bef){
		return maxd[now]=0;
	}
	for (long long next : adjl[now]){
		if (next==bef) continue;
		maxd[now]=max(maxd[now],dfs1(next,now,distnow+1)+1);
	}
	return maxd[now];
}

int main(){
	memset(maxd,-1,sizeof maxd);
	cin >> n >> t >> a;
	for (int i=0;i<n-1;i++){
		long long u, v;
		cin >> u >> v;
		adjl[u].push_back(v);
		adjl[v].push_back(u);
	}
	dfs1(a,0,0);
	long long tmp=0;
	while (dist>0){
//		cout << tmp << " " << maxd[t] << " " << dist << "\n";
		ans=max(ans,tmp+maxd[t]+dist-1);
		dist-=2;
		tmp++;
		t=par[t];
	}
	cout << ans << "\n";
}