    #include <bits/stdc++.h>
    using namespace std;
    using LL = long long;

    const int N = 234567;

    vector <int> G[N];
    int d[N], f[N], n, x, y;

    void dfs(int u, int p, int d[]) {
      for (auto v : G[u])
        if (v != p) {
          d[v] = d[u] + 1;
          dfs(v, u, d);
        }
    }

    int main() {
      cin >> n >> x >> y;
      for (int i = 1; i < n; i ++) {
        int u, v;
        scanf("%d %d", &u, &v);
        G[u].push_back(v); G[v].push_back(u);
      }
      dfs(y, 0, f);
      dfs(x, 0, d);
      int ans = 0;
      for (int i = 1; i <= n; i ++) {
        if (f[i] > d[i]) ans = max(ans, f[i]);
      }
      cout << ans-1 << endl;
      return 0;
    }
