#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<int>> d(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    d[a].push_back(b);
    d[b].push_back(a);
  }
  if (d[u].size() == 1 && d[u][0] == v) {
    cout << 0 << endl;
    return 0;
  }
  queue<P> que;
  que.push(P(u, 1));
  que.push(P(v, -1));
  vector<int> seen(n);
  seen[u] = 1;
  seen[v] = -1;
  bool flag = false;
  int pos = 0;
  while (!flag) {
    P p = que.front();
    que.pop();
    int v = p.first;
    for (int nx : d[v]) {
      if (seen[nx] == 0) {
        seen[nx] = p.second;
        que.push(P(nx, seen[nx]));
      } else if (seen[nx] == p.second) {
      } else if (p.second == 1) {
        pos = v;
        flag = true;
        break;
      } else if (p.second == -1) {
        seen[nx] = -1;
        for (int j : d[nx]) {
          if (seen[j] == 1) {
            pos = j;
            flag = true;
          }
          if (flag) break;
        }
      }
      if (flag) break;
    }
  }
  if (pos == u) {
    cout << 1 << endl;
    return 0;
  }
  vector<ll> dis(n);
  function<void(int, int)> dfs = [&](int before, int now) {
    for (int nx : d[now]) {
      if (nx == before) continue;
      dis[nx] = dis[now] + 1;
      dfs(now, nx);
    }
  };
  for (int nx : d[pos]) {
    if (seen[nx] == -1) continue;
    dis[nx] = 1;
    dfs(pos, nx);
  }
  ll ma = 0;
  for (int i = 0; i < n; i++) {
    ma = max(ma, dis[i]);
  }
  cout << dis[u] + ma << endl;
}
