#include<bits/stdc++.h>
#define f(i,a,b) for(long long i=a;i<b;i++)
#define pb(i) push_back(i)
typedef long long ll;
using namespace std;

int main(){
	ll n,u,v,a,b;
	cin>>n>>u>>v;
	vector<ll> vec[n+1];
	ll p=n-1,src=v;
	while(p--){
		cin>>a>>b;vec[a].pb(b);vec[b].pb(a);
	}
	if(vec[u].size()==1 and vec[u][0]==v){cout<<"0\n";return 0;}
	queue<ll> q;q.push(src);
	ll dist[n+1]={0};
	ll vis[n+1]={0};vis[src]=1;
	while(!q.empty()){
		ll node=q.front();q.pop();
		ll d=dist[node];
		f(i,0,vec[node].size()){
			if(vis[vec[node][i]]==0){
				dist[vec[node][i]]=d+1;
				q.push(vec[node][i]);
				vis[vec[node][i]]=1;
			}
		}
	}
	ll d=0;
	f(i,1,n+1) {
		d=max(d,dist[i]);
	}
	cout<<d-1<<"\n";
}