#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<PP,vector<PP>,greater<PP>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
vvi g;
vi di;
ll depth,k,a,b,from,f;
vi use;
bool dfs(ll i,ll p){
  use[i]=1;
  if(i==a){
    depth=di[i];
    return true;
  }
  for(ll u:g[i]){
    if(u!=p)if(dfs(u,i))return true;
  }
  use[i]=0;return false;
}
void dis(ll i,ll p){
  if(p!=-1)di[i]=di[p]+1;
  for(ll u:g[i])if(u!=p)dis(u,i);
}
int main(){
  ll n;cin>>n>>a>>b;
  g=vvi(n);
  use=vi(n);
  a--;b--;
  rep(i,n-1){
    ll c,d;cin>>c>>d;c--;d--;
    g[c].pb(d);
    g[d].pb(c);
  }
  di=vi(n);
  dis(b,-1);
  dfs(b,-1);
  rep(i,n)if(use[i]&&depth/2+1==di[i])from=i;
  for(ll o:g[from])if(di[o]<di[from])f=o;
  di=vi(n);di[f]=-1;
  dis(from,f);ll ma=0;
  rep(i,n)chmax(ma,di[i]);
  ll ans=depth/2+1+ma;
  if(ans%2!=(di[a]+di[ma])%2)ans--;
  cout<<ans<<endl;
}