#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

using namespace std;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct V {
    int num;
    int depth;
    V(){}
    V(int num, int depth) {
        this->num = num;
        this->depth = depth;
    }
};

int main(){
    int n,u,v; cin >> n >> u >> v;
    u--; v--;
    vector<vector<ll>> adj(n);
    rep(i, n-1) {
        int a,b; cin >> a >> b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<int> distfromAoki(n,0);
    vector<int> distfromTakahashi(n,0);

    queue<V> q;
    vector<int> visited1(n,0);
    q.push(V(u,0));
    // visited1[u] = 1;
    while(!q.empty()) {
        V next = q.front();
        q.pop();
        if(visited1[next.num] == 1)
            continue;
        visited1[next.num] = 1;
        distfromTakahashi[next.num] = next.depth;
        for(auto i : adj[next.num]) {
            q.push(V(i,next.depth+1));
        }
    }
    vector<int> visited2(n,0);
    q.push(V(v,0));
    // visited2[v] = 1;
    while(!q.empty()) {
        V next = q.front();
        q.pop();
        if(visited2[next.num] == 1)
            continue;
        visited2[next.num] = 1;
        distfromAoki[next.num] = next.depth;
        for(auto i : adj[next.num]) {
            q.push(V(i,next.depth+1));
        }
    }
    int x = -1;
    int dst;
    rep(i,n) {
        if(distfromTakahashi[i]==0)
            continue;
        // cout << distfromTakahashi[i] << " " << distfromAoki[i] << endl;
        int diff = distfromTakahashi[i] - distfromAoki[i];
        if(diff < 0 && distfromAoki[i] > x){
            // if((-diff)%2!=0) {
                if(x < distfromAoki[i]-1)
                    x = distfromAoki[i]-1;
            //
            // } else {
            //     if(x < distfromAoki[i]-2)
            //         x = distfromAoki[i]-2;
            // }
            dst = i;
        }
    }
    if(x==-1) {
        if(distfromTakahashi[v] ==1)
            cout << 0 << endl;
        else
            cout << 1 << endl;
        return 0;
    }
    // cout << dst << endl;
    cout << x << endl;
}
