#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (i64 i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (i64 i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<>>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? " " : "");
    outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? "\n" : "");
    outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
    cout << head;
    outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, int sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, int sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N, u, v);

    vector<vector<int>> G(N + 1);
    rep(i, N - 1) {
        var(int, a, b);
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    if (N == 2) {
        return outl(0), 0;
    }

    queue<int> que_u;
    que_u.emplace(u);

    vector<int> dist_u(N + 1, INF);
    dist_u[u] = 0;

    while (!que_u.empty()) {
        int nowNode = que_u.front();
        que_u.pop();
        for (auto nextNode: G[nowNode]) {
            if (chmin(dist_u[nextNode], dist_u[nowNode] + 1)) {
                que_u.emplace(nextNode);
            }
        }
    }

    queue<int> que_v;
    que_v.emplace(v);

    vector<int> dist_v(N + 1, INF);
    dist_v[v] = 0;

    while (!que_v.empty()) {
        int nowNode = que_v.front();
        que_v.pop();
        for (auto nextNode: G[nowNode]) {
            if (chmin(dist_v[nextNode], dist_v[nowNode] + 1)) {
                que_v.emplace(nextNode);
            }
        }
    }

    int maxu = -1, resIdx = 0;
    reps(i, 1, N) {
        if (dist_u[i] < dist_v[i]) {
            if (chmax(maxu, dist_u[i])) {
                resIdx = i;
            }
        }
    }


    outl(dist_v[resIdx] - 1);

    return 0;
}
