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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  int n,taka,aoki;
  cin>>n>>taka>>aoki;
  taka--;aoki--;
  vector<vector<ll>> adj(n);
  vector<ll> deg(n);
  rep(i,n-1){
    int u,v;
    cin>>u>>v;
    u--;v--;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
    deg[u]++;deg[v]++;
  }

  auto calcdist = [&](ll s){
    queue<pll> que;
    que.emplace(s,0);
    vector<ll> dist(n,INF);
    while(!que.empty()){
      ll v,c;
      tie(v,c) = que.front();
      que.pop();
      if(chmin(dist[v],c)){
        for(auto nv:adj[v]){
          que.emplace(nv,c+1);
        }
      }
    }
    return dist;
  };

  auto dist1 = calcdist(aoki);
  auto dist2 = calcdist(taka);

  vector<ll> leaf;
  rep(i,n)if(deg[i]==1)leaf.emplace_back(i);
  ll ans = 0;
  for(auto v:leaf){
    if(dist1[v]>dist2[v]){
      chmax(ans,dist2[v]+(dist1[v]&1?0:1));
    }
  }
  cout<<(ans)<<endl;


}