#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << endl
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;

  vvll to(N);
  rep(i, N - 1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].pb(b);
    to[b].pb(a);
  }

  queue<P> q1;
  q1.push({u, 1});
  vll d1(N);
  while (!q1.empty()) {
    ll index = q1.front().first;
    ll distance = q1.front().second;
    q1.pop();
    if (d1[index] != 0) continue;
    d1[index] = distance;
    rep(i, to[index].size()) {
      q1.push({to[index][i], distance + 1});
    }
  }

  debugV(d1);

  queue<P> q2;
  q2.push({v, 1});
  vll d2(N);
  while (!q2.empty()) {
    ll index = q2.front().first;
    ll distance = q2.front().second;
    q2.pop();
    if (d2[index] != 0) continue;
    d2[index] = distance;
    rep(i, to[index].size()) {
      q2.push({to[index][i], distance + 1});
    }
  }

  debugV(d2);

  ll ans = 0;
  rep(i, N) {
    if (d1[i] < d2[i]) ans = max(ans, d2[i]);
  }
  ans--;
  ans--;
  COUT(ans);
  return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int N,u,v;
    cin >> N >> u >> v;
    vector<vector<int>> A(N);
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        A[a-1].push_back(b-1);
        A[b-1].push_back(a-1);
    }
    queue<int> q1;
    q1.push(u-1);
    vector<int> D1(N,-1);
    D1[u-1]=0;
    while(q1.size()){
        int f=q1.front();
        q1.pop();
        for(int a:A[f]){
            if(D1[a]==-1){
                D1[a]=D1[f]+1;
                q1.push(a);
            }
        }
    }
    queue<int>q2;
    q2.push(v-1);
    vector<int>D2(N,-1);
    D2[v-1]=0;
    while(q2.size()){
        int f=q2.front();
        q2.pop();
        for(int a:A[f]){
            if(D2[a]==-1){
                D2[a]=D2[f]+1;
                q2.push(a);
            }
        }
    }
    
    vector<int> NG(N,0);
    int M=0,Mi=-1;
    for(int i=0;i<N;i++){
        NG[i]=(D2[i]-D1[i]<0);
        if((!NG[i]) && M<D2[i]){
            M=D2[i];
            Mi=i;
        }
    }
    if(NG[u-1]){
        cout << 0;
        return 0;
    }
    cout << D1[Mi]+(D2[Mi]-D1[Mi])-1 << "\n";
}