#include <bits/stdc++.h>

using namespace std;

int n, a, b;
int p[100010], d[100010], dp[100010];
vector<int> adj[100010];

void rootTree(int u, int par = -1){
    dp[u] = d[u];

    for(auto v : adj[u]){
        if(v == par) continue;

        p[v] = u;
        d[v] = d[u] + 1;
        rootTree(v, u);

        dp[u] = max(dp[u], dp[v]);
    }
}

int main(){
    scanf("%d%d%d", &n, &a, &b);

    for(int i = 1; i < n; i++){
        int u, v;
        scanf("%d%d", &u, &v);

        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }

    memset(p, -1, sizeof(p));

    rootTree(b);

    int ans = 0, dep = 0;

    while(d[a] > dep){
        //Test for a
        ans = max(ans, dp[a] - 1);

        a = p[a];
        dep++;
    }

    printf("%d\n", ans);

    return 0;
}