#include<iostream>
#include<vector>
#include<functional>
using namespace std;

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    a--, b--;
    vector<int> v[n];
    for(int i = 0; i < n-1; i++){
        int x, y;
        cin >> x >> y;
        x--, y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    function<void(vector<int>&,int,int,int)> f = [&](vector<int> &d, int x, int par, int dep){
        d[x] = dep;
        for(int y : v[x]){
            if(y != par)    f(d, y, x, dep+1);
        }
    };
    vector<int> tak(n), aoki(n);
    f(tak, a, -1, 0);
    f(aoki, b, -1, 0);
    int ret = 0;
    for(int i = 0; i < n; i++){
        if(tak[i] < aoki[i])    ret = max(ret, aoki[i]-1);
    }
    cout << ret << endl;
    return 0;
}