#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, t, a;
  cin >> n >> t >> a;
  --t;
  --a;
  vector<vector<int>> g(n);
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<int> dt(n, 0), da(n, 0);
  function<void(int, int)> Dfst = [&](int v, int pv) {
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      dt[u] = dt[v] + 1;
      Dfst(u, v);
    }
  };
  function<void(int, int)> Dfsa = [&](int v, int pv) {
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      da[u] = da[v] + 1;
      Dfsa(u, v);
    }
  };
  Dfst(t, -1);
  vector<vector<int>> base(n);
  for (int i = 0; i < n; i++) {
    base[dt[i]].push_back(i);
  }
  Dfsa(a, -1);
  for (int i = 0; i < n; i++) {
    bool done = true;
    for (int v : base[i]) {
      if (da[v] > i) {
        done = false;
      }
    }
    if (done) {
      cout << i - 1 << '\n';
      return 0;
    }
  }
  cout << *max_element(da.begin(), da.end()) - 1 << '\n';
  return 0;
}
