#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010
ll n,a,b,h[M],p[M];
vll g[M];

int main(){
	IOS;
	cin>>n>>a>>b;
	rep(i,0,n)h[i]=-1,p[i]=i;
	a--,b--;
	rep(i,0,n-1){
		ll u,v;cin>>u>>v;u--,v--;
		g[u].pb(v),g[v].pb(u);
	}
	queue<ll>q;
	q.push(b);h[b]=0;
	while(!q.empty()){
		ll u=q.front();q.pop();
		for(auto v:g[u])if(h[v]==-1)h[v]=h[u]+1,q.push(v);
	}
	q.push(b);
	while(!q.empty()){
		ll u=q.front();q.pop();
		for(auto v:g[u]){
			if(p[v]==v){
				p[v]=u;
				if(v==a)break;
				q.push(v);
			}
		}
	}
	vll path;
	ll u=a;
	while(u!=b)path.pb(u),u=p[u];
	path.pb(b);
	ll t=0,i=0,j=sz(path)-1,dif;
	while(1){
		if(i+1<j-1)i++;
		else {
			dif=(j-i);
			break;
		}
		j--,t++;
	}
	ll ht=h[i];
	if(dif==1)t+=(ht);
	else t+=(ht);
	cout<<t;
	return 0;
}

