#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

struct node {
    int aoki;
    vector<int> neighbor;

    bool isLeaf() const {
        return neighbor.size() == 1;
    }
};

using graph = vector<node>;

void aoki(int s, graph& g) {
    function<void(int, int)> rec = [&](int v, int bv) {
        for (int u : g[v].neighbor) {
            if (u != bv) {
                g[u].aoki = g[v].aoki + 1;
                rec(u, v);
            }
        }
    };

    g[s].aoki = 0; 
    rec(s, -1);
}

int takahashi(int s, graph& g) {
    function<int(int, int, int)> rec = [&](int v, int bv, int step) {
        if (g[v].aoki <= step || g[v].aoki - step == 1 && g[v].isLeaf()) {
            return step;
        }
        
        int ret = 0;

        for (int u : g[v].neighbor) {
            if (u != bv) {
                ret = max(ret, rec(u, v, step + 1));
            }
        }
    
        return ret;
    };

    return rec(s, -1, 0);
}

int main() {
    int n, u, v; cin >> n >> u >> v;
    --u; --v;
    
    graph g(n);

    REP(i, n-1) {
        int a, b; cin >> a >> b;
        --a; --b;
        g[a].neighbor.push_back(b);
        g[b].neighbor.push_back(a);
    }

    aoki(v, g);

    cout << takahashi(u, g) << endl;

    return 0;
}
