#include <bits/stdc++.h>

using namespace std;

const int N = 100005;
vector<int> g[N];

void dfs(int v, int p, vector<int> & d) {
    for (int nxt : g[v]) {
        if (nxt == p) continue;
        d[nxt] = d[v]+1;
        dfs(nxt, v, d);
    }
}

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

    int n, t, a;
    cin >> n >> t >> a;
    a--;
    t--;
    for (int j = 0; j < n-1; j++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    vector<int> dt(n);
    dt[t] = 0;
    dfs(t, -1, dt);

    vector<int> da(n);
    da[a] = 0;
    dfs(a, -1, da);

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (dt[i] < da[i]) {
            ans = max(ans, da[i] - 1);
        }
    }
    cout << ans << endl;

    return 0;
}

