#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> G;
vector<int> du, dv;
void dfsu(int s, int d){
    du[s] = d;
    for(int i: G[s]){
        if(du[i] == -1) dfsu(i, d + 1);
    }
}
void dfsv(int s, int d){
    dv[s] = d;
    for(int i: G[s]){
        if(dv[i] == -1) dfsv(i, d + 1);
    }
}
int main(){
    int N, u, v;
    cin >> N >> u >> v;
    u--;
    v--;
    G.resize(N);
    du.resize(N, -1);
    dv.resize(N, -1);
    for(int i = 0; i < N - 1; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfsu(u, 0);
    dfsv(v, 0);
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(du[i] < dv[i]) {
            ans = max(ans, dv[i] - 1);
        }
    }
    cout << ans << endl;
}