#include <bits/stdc++.h>
using namespace std;
int n,A,B,depth,dep[100005],p[100005],T[100005];
vector < int > v[100005];
void Dfs(int x,int y) {
	p[x]=y,dep[x]=++depth,T[x]=0;
	for (int i=0; i<v[x].size(); i++) {
		if (v[x][i]==p[x]) continue;
		Dfs(v[x][i],x);
		T[x]=max(T[x],T[v[x][i]]);
	}
	T[x]++;
	--depth;
}
main () {
	cin>>n>>A>>B;
	for (int i=1; i<n; i++) {
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	
	Dfs(B,B);
	
	int len=dep[A],ans=0,cur=0;
	while (A!=B) {
		ans=max(ans,cur+max(0,T[A]-1));
		cur++;
		A=p[A];
		if (len-cur<1+cur) break;
		if (len-cur==1+cur) {
			ans=max(ans,cur);
			break;
		}	
	}
	
	cout<<ans<<endl;
}