#include <bits/stdc++.h>
using namespace std;
int N, u, v;
vector<vector<int>> G;

void dfs(vector<int> &D, int c) {
    for(int to : G[c]) {
        if(D[to] == -1) {
            D[to] = D[c] + 1;
            dfs(D, to);
        }
    }
}

int main() {
    cin >> N >> u >> v;
    --u; --v;
    G.assign(N, vector<int>());
    for(int i=1; i<N; ++i) {
        int a, b; cin >> a >> b;
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> T(N, -1), A(N, -1);
    T[u] = 0; A[v] = 0;
    dfs(T, u);
    dfs(A, v);

    int res = 0;
    for(int i=0; i<N; ++i) {
        if(T[i] <= A[i]) res = max(res, A[i] - 1);
    }
    cout << res << endl;
}