#include <functional>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n, u, v; cin >> n >> u >> v;
    u--; v--;
    vector<int> adj[n];
    for (int j = 0; j < n-1; j++) {
        int a, b; cin >> a >> b;
        adj[a-1].push_back(b-1);
        adj[b-1].push_back(a-1);
    }
    int du[n], dv[n];
    function<void(int, int, int, int*)>
        dfs = [&adj, &dfs](int i, int p, int l, int *d) {
        d[i] = l;
        for (int j : adj[i]) if (j != p) dfs(j, i, l+1, d);
    };
    dfs(u, -1, 0, du);
    dfs(v, -1, 0, dv);
    int ans = 0;
    for (int i = 0; i < n; i++)
        if (du[i] < dv[i]) ans = max(ans, dv[i] - 1);
    cout << ans << endl;
}
