#include<bits/stdc++.h>
using namespace std;

int n;
vector<int> to[100005];
vector<int> dist;

void dfs(int v, int d = 0, int p = -1){
    dist[v] = d;
    for(int u : to[v]){
        if(u == p) continue;
        dfs(u, d+1, v);
    }
}

vector<int> calcDist(int s){
    dist = vector<int>(n);
    dfs(s);
    return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s, t;
    cin >> n >> s >> t;
    s--; t--;
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<int> distS = calcDist(s);
    vector<int> distT = calcDist(t);
    int mx = 0;
    for(int i = 0; i < n; i++){
        if(distS[i] < distT[i]) mx = max(mx, distT[i]);
    }
    int ans = mx - 1;
    cout << ans << endl;
    return 0;
}