#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll mod = 1000000007;
const ll inf = 1e18;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
template <typename T>
void print_vec(vector<T> a) {
  int n = a.size();
  for (ll i = 0; i < (n); ++i) {
    cout >> a[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << endl;
  }
}
ll power(ll base, ll exponent) {
  if (exponent % 2) {
    return power(base, exponent - 1) * base % mod;
  } else if (exponent) {
    ll root_ans = power(base, exponent / 2);
    return root_ans * root_ans % mod;
  } else {
    return 1;
  }
}
ll inverse(ll x) { return power(x, mod - 2); }
ll gcd(ll a, ll b) {
  if (a < b) gcd(b, a);
  ll r;
  while (r = a % b) {
    a = b;
    b = r;
  }
  return b;
}
template <typename T>
ll sum(T begin, T end) {
  return accumulate(begin, end, 0ll);
}
struct combination {
  vector<ll> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1) {
    fact[0] = 1;
    for (int i = 1; i <= sz; i++) {
      fact[i] = fact[i - 1] * i % mod;
    }
    inv[sz] = power(fact[sz], mod - 2);
    for (int i = sz - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % mod;
    }
  }
  ll C(int p, int q) const {
    if (q < 0 || p < q) return 0;
    return (fact[p] * inv[q] % mod * inv[p - q] % mod);
  }
};
using Pair = pair<ll, ll>;
vector<vector<ll>> g;
signed main() {
  ios::sync_with_stdio(false);
  ll n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  g.resize(n);
  for (ll i = 0; i < (n - 1); ++i) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<ll> nt(n, -1);
  nt[v] = 0;
  queue<Pair> q;
  q.emplace(v, 0);
  while (q.size()) {
    auto c = q.front();
    q.pop();
    for (ll i = 0; i < (int(g[c.first].size())); ++i) {
      ll j = g[c.first][i];
      if (nt[j] != -1) continue;
      nt[j] = c.second + 1;
      q.emplace(j, nt[j]);
    }
  }
  q.emplace(u, 0);
  vector<ll> nv(n, -1);
  vector<ll> can(n);
  while (q.size()) {
    auto c = q.front();
    q.pop();
    for (ll i = 0; i < (int(g[c.first].size())); ++i) {
      ll j = g[c.first][i];
      if (nt[j] < c.second || can[j] == 1) continue;
      if (nt[j] == c.second + 1) {
        can[j] = 1;
        nt[j]++;
        continue;
      }
      can[j] = 1;
      nv[j] = c.second + 1;
      q.emplace(j, c.second + 1);
    }
  }
  ll ans = 0;
  for (ll i = 0; i < (n); ++i) {
    if (can[i]) {
      ans = max(ans, nt[i]);
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
