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

void dfs(int node, int father, vector<vector<int>>& ad, vector<int>& dist) {
    dist[node] = dist[father] + 1;
    for (int nghb : ad[node])
        if (nghb != father)
            dfs(nghb, node, ad, dist);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, a, b;
    cin >> n >> a >> b;

    vector<vector<int>> ad(n + 1);
    for (int i = 1; i < n; i++) {
        int x, y; cin >> x >> y;
        ad[x].push_back(y);
        ad[y].push_back(x);
    }

    vector<int> distA(n + 1);
    dfs(a, 0, ad, distA);

    vector<int> distB(n + 1);
    dfs(b, 0, ad, distB);

    int best = 0;
    for (int i = 1; i <= n; i++)
        if (distA[i] <= distB[i])
            best = max(best, distB[i]);

    cout << best - 2 << '\n';
    return 0;
}
