#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;
const int INF = (ll)1e9 + 7;
const ll INFLL = (ll)1e18;
const double EPS = 1e-5;
using namespace std;
template <class t>
using vvector = vector<vector<t>>;
template <class t>
using vvvector = vector<vector<vector<t>>>;
template <class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template <class t, class u>
bool chmax(t &a, u b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class t, class u>
bool chmin(t &a, u b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
ll modpow(ll x, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1) res = res * x % MOD;
    x = x * x % MOD;
    b >>= 1;
  }
  return res;
}
ll modinv(ll x) { return modpow(x, MOD - 2); }
bool was_output = false;
template <class t>
void output(t a) {
  if (was_output) cout << " ";
  cout << a;
  was_output = true;
}
void outendl() {
  was_output = false;
  cout << endl;
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  vvector<int> edges(n);
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  vector<int> tf(n, INF);
  vector<int> af(n, INF);
  tf[u] = 0;
  af[v] = 0;
  stack<int> st;
  st.push(v);
  while (st.size()) {
    int d = st.top();
    st.pop();
    for (auto &i : (edges[d])) {
      if (af[i] <= af[d] + 1) continue;
      af[i] = af[d] + 1;
      st.push(i);
    }
  }
  int ans = 0;
  st.push(u);
  while (st.size()) {
    int d = st.top();
    st.pop();
    chmax(ans, af[d] - 1 ^ (1 & tf[d] & af[d]));
    for (auto &i : (edges[d])) {
      if (tf[i] <= tf[d] + 1) continue;
      tf[i] = tf[d] + 1;
      if (tf[i] > af[i]) continue;
      st.push(i);
    }
  }
  cout << ans << endl;
}
