#include <bits/stdc++.h>

using namespace std;

const int M = 1e5;
vector<int> adj[M];
int distU[M], distV[M];

void calc(int cur, int parent, int dist, int *distArr) {
    distArr[cur] = dist;
    for (int x : adj[cur])
        if (x != parent)
            calc(x, cur, dist + 1, distArr);
}

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

    int n, u, v, ans = 0;
    cin >> n >> u >> v;
    u--;
    v--;

    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    calc(u, -1, 0, distU);
    calc(v, -1, 0, distV);

    for (int i = 0; i < n; i++)
        if (distU[i] < distV[i])
            ans = max(ans, distV[i]);

    cout << ans - 1 << "\n";

    return 0;
}