#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;
vector<int> dt;
vector<int> da;
vector<int> tstop;
void dfs(vector<int> &d, const int &cnt, const int &par, const bool &t) {
  if (t && g[cnt].size() == 1) {
    tstop.push_back(cnt);
  }
  for (auto x : g[cnt]) {
    if (x == par) {
      continue;
    }
    d[x] = d[cnt] + 1;
    if (t && dt[x] == da[x]) {
      continue;
    }
    dfs(d, x, cnt, t);
  }
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  dt.resize(n);
  da.resize(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, false);
  dfs(dt, u, -1, true);
  for (auto x : tstop) {
    dt[g[x][0]] = da[g[x][0]];
    dt[x] = da[g[x][0]];
  }
  int ans = 0;
  for (int i = 0; i < (n); i++) {
    if (dt[i] == da[i]) {
      ans = max(ans, da[i]);
    }
  }
  if (g[u].size() == 0 && g[u][0] == v)
    cout << (0) << '\n';
  else
    cout << ans << '\n';
  return 0;
}
