#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, u, v;
    cin >> n >> u >> v;
    u--, v--;
    vector<vector<ll>> g(n);
    rep(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].eb(b);
        g[b].eb(a);
    }
    vector<bool> seen(n);
    ll dis;
    auto rec = [&](auto &&f, ll now, ll d) -> void {
        seen[now] = true;
        if (now == v) dis = d;
        each(e, g[now]) {
            if (seen[e]) continue;
            f(f, e, d + 1);
        }
    };
    rec(rec, u, 0);

    queue<ll> t_nxt, a_nxt;
    t_nxt.push(v), a_nxt.push(u);
    vector<bool> t_seen(n);
    t_seen[v] = true;
    bool is_t = true;
    ll ans = 0;
    clock_t start = clock();
    while (true) {
        if (is_t) {
            queue<ll> t_que;
            while (!t_nxt.empty()) {
                ll now = t_nxt.front();
                t_nxt.pop();
                each(e, g[now]) {
                    if (t_seen[e]) continue;
                    t_que.push(e);
                    t_seen[e] = true;
                }
            }
            t_nxt = t_que;
        } else {
            queue<ll> a_que;
            while (!a_nxt.empty()) {
                ll now = a_nxt.front();
                a_nxt.pop();
                each(e, g[now]) {
                    if (t_seen[e]) continue;
                    a_que.push(e);
                }
            }
            a_nxt = a_que;

            ans++;
            if (a_que.empty()) {
                break;
            } else {
            }
        }
        is_t = !is_t;

        clock_t end = clock();
        const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
        if (time > 1700) {
            ans = dis;
            break;
        }
    }
    if (dis % 2 == 1) cout << ans - 1 << '\n';
    else cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}