#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int N, u, v;
vector<vector<int>> links;


void input() {
    cin >> N >> u >> v;
    u--;
    v--;
    links = vector<vector<int>>(N);
    rep(i, N-1) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        links[A].push_back(B);
        links[B].push_back(A);
    }
}


void dfs(vector<int>& dlist, int num, int p, int d) {
    dlist[num] = d;
    for (int i : links[num]) {
        if (i == p) continue;
        dfs(dlist, i, num, d+1);
    }
}


int main() {
    input();
    vector<int> ud, vd;
    ud = vd = vector<int>(N);
    dfs(ud, u, -1, 0);
    dfs(vd, v, -1, 0);
    int ans = 0;
    rep(i, N) {
        if (ud[i] < vd[i]) ans = max(ans, vd[i]-1);
    }
    cout << ans << endl;
}
