#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
vector<vector<int>> g;
void dfs(vector<int> &d, const int &cnt, const int &par) {
  if (par != -1) d[cnt] = d[par] + 1;
  for (auto x : g[cnt]) {
    if (x == par) continue;
    dfs(d, x, cnt);
  }
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<int> dt(n);
  vector<int> da(n);
  g.resize(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);
  }
  dfs(da, v, -1);
  vector<tuple<int, int, bool>> t;
  t.push_back(make_tuple(u, -1, false));
  int ans = 0;
  while (true) {
    vector<tuple<int, int, bool>> tmp;
    swap(tmp, t);
    for (auto it = tmp.begin(); it != tmp.end(); it++) {
      if (ans < da[get<0>(*it)]) t.push_back(*it);
    }
    if (t.empty()) break;
    tmp.clear();
    swap(tmp, t);
    for (auto x : tmp) {
      for (auto y : g[get<0>(x)]) {
        if (get<2>(x)) {
          if (y == get<1>(x))
            t.push_back(make_tuple(get<1>(x), get<0>(x), true));
          continue;
        } else if (y == get<1>(x)) {
          if (get<1>(x) != -1 && g[get<0>(x)].size() == 1) {
            t.push_back(make_tuple(get<1>(x), get<0>(x), true));
          } else
            continue;
        } else {
          t.push_back(make_tuple(y, get<0>(x), false));
        }
      }
    }
    tmp.clear();
    swap(tmp, t);
    for (auto it = tmp.begin(); it != tmp.end(); it++) {
      if (ans < da[get<0>(*it)]) t.push_back(*it);
    }
    if (t.empty()) break;
    ans++;
  }
  cout << ans << '\n';
  return 0;
}
