#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

ll n;
vector<lvector> G(n);
lvector dist;

void dfs(ll v, ll d=0, ll p=-1) {
  dist[v]=d;
  for(ll u:G[v]) {
    if(u==p) continue;
    dfs(u,d+1,v);
  }
  return;
}

lvector get_distance(ll s) {
  dist=lvector(n,0);
  dfs(s);
  return dist;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll u,v,a,b,ans=0;cin>>n>>u>>v;
  u--; v--;
  G.resize(n);
  rep(i,n-1) {
    cin>>a>>b; a--; b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  lvector distT=get_distance(u);
  lvector distA=get_distance(v);
  rep(i,n) if(distT[i]<distA[i]) ans=max(ans,distA[i]);
  print(ans-1);
  return 0;
}