#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
using UnWeightedGraph = vector<vector<int> >;
 
int n;
int uv, vv;
UnWeightedGraph G;
vector<int> euler_tour;
vector<int> L, R;
vector<int> d1, d2;
int k = 0;
 
void dfs(int v, int p) {
  L[v] = k++;
  euler_tour.emplace_back(v);
 
  for ( int u : G[v] ) {
    if ( u == p ) continue;
    dfs(u, v);
    euler_tour.emplace_back(v);
  }
 
  R[v] = k++;
}
 
struct RUP {
  int n;
  vector<int> dat, laz;
  const int def = 0;
  
  RUP() {}
  RUP(int n_) { init(n_); }
  
  void init(int n_) {
    n = 1;
    while ( n < n_ ) n *= 2;
    dat.clear();
    dat.resize(2*n-1, def);
    laz.clear();
    laz.resize(2*n-1, -1);    
  }
 
  inline void eval(int len, int k) {
    if ( laz[k] < 0 ) return;
    if ( k*2+1 < n*2-1 ) {
      laz[k*2+1] = laz[k];
      laz[k*2+2] = laz[k];
    }
    dat[k] = laz[k];
    laz[k] = -1;    
  }
 
  int update(int a, int b, int x, int k, int l, int r) {
    eval(r-l, k);
    if ( r <= a || b <= l ) return dat[k];
    if ( a <= l && r <= b ) return laz[k] = x;
    eval(r-l, k);
    dat[k] = max(update(a, b, x, k*2+1, l, (l+r)/2),
		 update(a, b, x, k*2+2, (l+r)/2, r));
    return dat[k];    
  }
 
  int query(int a, int b, int k, int l, int r) {
    eval(r-l, k);
    if ( r <= a || b <= l ) return def;
    if ( a <= l && r <= b ) return dat[k];
    int vl = query(a, b, k*2+1, l, (l+r)/2);
    int vr = query(a, b, k*2+2, (l+r)/2, r);
    return max(vl, vr);    
  }
 
  void update(int a, int b, int x) {
    update(a, b, x, 0, 0, n);    
  }
 
  int query(int a, int b) {
    return query(a, b, 0, 0, n);    
  }
};

using Pii = pair<int, int>;

int solve(int s, vector<int> &D) {  
  bool used[n];
  fill_n(used, n, false);
  queue<Pii> Q;
  Q.push(Pii(s, 0));
  while ( !Q.empty() ) {
    Pii q = Q.front(); Q.pop();
    int u = q.first, c = q.second;

    if ( used[u] ) continue;
    used[u] = true;
    D[u] = c;

    for ( int v: G[u] ) {
      if ( used[v] ) continue;
      Q.push(Pii(v, c+1));      
    }    
  }
}
 
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  cin >> n >> uv >> vv;
  uv--; vv--;  
  
  G = UnWeightedGraph(n);
  for ( int i = 0; i < n-1; i++ ) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
 
  L = R = vector<int>(n);
  d1 = d2 = vector<int>(n, 0);
  solve(uv, d1);
  solve(vv, d2);
  dfs(vv, -1);
 
  int N = euler_tour.size();
  /* for ( int i : euler_tour ) cout << i << " ";
     cout << endl;
     for ( int i = 0; i < n; i++ ) {
     cout << i << " " << L[i] << " " << R[i] << endl;
     } */  
  RUP seg1(N), seg2(N);
  for ( int i = 0; i < n; i++ ) {
    if ( d1[i] < d2[i] ) seg1.update(L[i], R[i], 1);    
  }

  // for ( int i = 0; i < n; i++ ) cout << d2[i] << endl;

  int ma = 0;
  for ( int i = 0; i < n; i++ ) {
    if ( seg1.query(L[i], L[i]+1) == 1 ) {    
      ma = max(ma, d2[i]-1);
    }
  }

  cout << ma << endl;
  /*
  int q;
  cin >> q;
  for ( int i = 1; i <= q; i++ ) {
    int c, v;
    cin >> c >> v;
    v--;
    if ( c == 1 ) {
      seg1.update(L[v], R[v], i);      
    }
    else if ( c == 2 ) {
      seg2.update(L[v], L[v]+1, i);      
    }
    else {
      if ( seg1.query(L[v], L[v]+1) > seg2.query(L[v], R[v]) ) cout << 1 << endl;      
      else cout << 0 << endl;
    }
  }
  */  
  
  return 0;
}


Measured memory_bytes: 30960