}#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  ll n;cin>>n;
  ll u,k;cin>>u>>k;
  u--;k--;
  vector<ll> v[n];
  REP(i,n-1){
    ll a,b;cin>>a>>b;
    a--;b--;
    v[a].pb(b);
    v[b].pb(a);
  }

  ll aoki[n];
  REP(i,n){
    aoki[i] = -1;
  }

  aoki[k] = 0;

  queue<ll> q;
  q.push(k);
  while(!q.empty()){
    ll l = q.front();
    ll now = aoki[l];
    q.pop();
    REP(i,v[l].size()){
      if(aoki[v[l][i]] == -1){
        aoki[v[l][i]] = now + 1;
        q.push(v[l][i]);
      }
    }
  }

  

  ll taka[n];
  REP(i,n){
    taka[i] = -1;
  }

  taka[u] = 0;
  q.push(u);

  while(!q.empty()){
    ll l = q.front();
    ll now = taka[l];
    q.pop();
    REP(i,v[l].size()){
      ll next = v[l][i];
      if(aoki[next] >= now + 1){
        taka[next] = now + 1;
        if(aoki[next] > now + 1)q.push(next);
      }
    }
  }

  /*REP(i,n){
    cout<<i+1<<" aoki= "<<aoki[i]<<" taka= "<<taka[i]<<endl;
  }*/

  ll ans = 0;
  REP(i,n){
    ans = max(ans,taka[i]);
  }
  cout<<ans<<endl;
  

  return 0;
}