#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    ll n, u, v;
    cin >> n >> u >> v;

    vector<vector<ll>> g(n + 1);
    rep(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    queue<ll> q;
    q.push(u);

    ll distance_t[n + 1] = {}, distance_a[n + 1] = {};

    rep(i, n + 1) {
        distance_t[i] = -1;
        distance_a[i] = -1;
    }

    distance_t[u] = 0;
    distance_a[v] = 0;

    q.push(u);
    while (!q.empty()) {
        ll now = q.front();
        q.pop();
        ll distance_now = distance_t[now];
        rep(i, g[now].size()) {
            ll next = g[now][i];
            if (distance_t[next] == -1) {
                q.push(next);
                distance_t[next] = distance_now + 1;
            }
        }
    }

    q.push(v);
    while (!q.empty()) {
        ll now = q.front();
        q.pop();
        ll distance_now = distance_a[now];
        rep(i, g[now].size()) {
            ll next = g[now][i];
            if (distance_a[next] == -1) {
                q.push(next);
                distance_a[next] = distance_now + 1;
            }
        }
    }

    // rep(i, n + 1) { cout << distance_t[i] << " " << distance_a[i] << endl; }

    ll ans = 0;
    repd(i, 1, n + 1) {
        if (distance_t[i] < distance_a[i]) {
            ll d = distance_a[i] - distance_t[i];
            ll ans_temp = distance_t[i] + d / 2;
            // cout << "here" << i << " " << ans_temp << endl;
            ans = max(ans, ans_temp);
        }
    }

    cout << ans << endl;
    return 0;
}

