#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> t, a;
void dfs(vector<int> &v, int par, int cnt, bool t) {
  if (par != -1) v[cnt] = v[par] + 1;
  if (t && a[cnt] <= v[cnt]) return;
  for (auto x : g[cnt]) {
    if (x == par) continue;
    if (t && a[x] < v[cnt]) continue;
    dfs(v, cnt, x, t);
  }
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  g.resize(n);
  t.resize(n);
  a.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);
  }
  if (g[u].size() == 1 && g[u][0] == v) {
    cout << (0) << '\n';
    return 0;
  }
  dfs(a, -1, v, false);
  dfs(t, -1, u, true);
  cout << *max_element((t).begin(), (t).end()) << endl;
  return 0;
}
