#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> E;
vector<bool> visited;

void dfs(int i, int d, vector<int> &A){
    if (visited[i])
        return;
    visited[i] = true;
    A[i] = d;
    for (const auto &e: E[i])
        dfs(e, d + 1, A);
}

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

    
    vector<int> d_a(n), d_b(n);
    visited.assign(n, false);

    dfs(u, 0, d_a);
    visited.assign(n, false);
    dfs(v, 0, d_b);

    int ans = 0;
    for (int i = 0; i < n; i++){
        if (d_a[i] < d_b[i]){
            ans = max(ans, d_b[i]);
        }
    }

    cout << ans - 1 << endl;
}