#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T gcd(T a, T b) {
  if (a < b) std::swap(a, b);
  while (b) std::swap(a %= b, b);
  return a;
}
template <class T>
T lcm(const T a, const T b) {
  return a / gcd(a, b) * b;
}
using ll = long signed long;
using ull = long unsigned long;
using ld = long double;
using namespace std;
struct inp {
  size_t sz;
  inp(size_t _sz = 1) : sz(_sz) {}
  template <typename T>
  operator T() const {
    T a;
    cin >> a;
    return a;
  }
  template <typename T>
  operator vector<T>() const {
    vector<T> a(sz);
    for (size_t i = 0; i < sz; i++) cin >> a[i];
    return a;
  }
  template <typename T, typename U>
  operator pair<T, U>() const {
    T f;
    U s;
    cin >> f >> s;
    return pair<T, U>(f, s);
  }
};
inp inp1;
template <typename T>
void say(T &x, char end = '\n') {
  cout << x << end;
}
template <typename T>
void say(vector<T> &x, char sep = ' ', char end = '\n') {
  for (size_t i = 0, sz = x.size(); i < sz; i++) {
    cout << x[i] << (i == sz - 1 ? end : sep);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n = inp1;
  ll u = inp1;
  ll v = inp1;
  u--;
  v--;
  vector<vector<ll>> g(n);
  vector<ll> deg(n, 0);
  vector<bool> is_leaf(n, false);
  for (long long i = 0, i_len = (n - 1); i < i_len; i++) {
    ll a = inp1, b = inp1;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
    deg[a]++;
    deg[b]++;
  }
  for (long long i = 0, i_len = (n); i < i_len; i++) {
    is_leaf[i] = deg[i] == 1 && i != v;
  }
  vector<ll> dp(n, -1), dq(n, -1);
  {
    deque<ll> q = {v};
    dp[v] = 0;
    while (q.size()) {
      ll i = q.front();
      q.pop_front();
      for (ll j : g[i]) {
        if (dp[j] == -1) {
          dp[j] = dp[i] + 1;
          q.push_back(j);
        }
      }
    }
  }
  {
    deque<ll> q = {u};
    dq[u] = 0;
    while (q.size()) {
      ll i = q.front();
      q.pop_front();
      if (dp[i] <= dq[i]) continue;
      for (ll j : g[i]) {
        if (dq[j] == -1 && dq[i] + 1 <= dp[j]) {
          dq[j] = dq[i] + 1;
          q.push_back(j);
        }
      }
    }
  }
  ll ans = 0;
  for (long long i = 0, i_len = (n); i < i_len; i++) {
    ll cand = dq[i];
    if (is_leaf[i] && (dp[i] + dq[i]) % 2 == 0) {
      cand--;
    }
    chmax(ans, dq[i]);
  }
  say(ans);
}
