#include <bits/stdc++.h>
using namespace std;

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y)      REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z)   REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
#define ncinp(n, p)         REP(i, 0, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }
#define ncin1_1(n, x)       REPE(i, 1, n) { cin1(x[i]); }
#define ncin2_1(n, x, y)    REPE(i, 1, n) { cin2(x[i], y[i]); }
#define ncin3_1(n, x, y, z) REPE(i, 1, n) { cin3(x[i], y[i], z[i]); }
#define ncinp_1(n, p)       REPE(i, 1, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;


vlli G[100001];

int main() {
    lli n,u,v;
    cin3(n,u,v);
    lli a[n-1];
    lli b[n-1];
    ncin2(n-1,a,b);

    REP(i,0,n-1) {
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }


    // v からの距離
    lli length[n+1] = {0};
    queue<P> que;

    que.push(make_pair(v,0));
    length[v] = 0;
    while(!que.empty()) {
        lli cur, l;
        tie(cur,l) = que.front();
        que.pop();

        REP(i,0,G[cur].size()) {
            lli next = G[cur][i];
            if (length[next] != 0 || next == v)
                continue;
            length[next] = l+1;
            que.push(make_pair(next, l+1));
        }
    }
    //REPE(i,1,n) {
    //    cout << length[i] << endl;
    //}

    lli limit = length[u]/2 + 1;
    // limit 以上の値のところならいける
    queue<lli> que2;
    que2.push(u);
    bool used[n+1] { false };
    lli ans_max = length[u];
    used[u] = true;
    while (!que2.empty()) {
        lli cur = que2.front();
        que2.pop();
        ans_max = max(length[ans_max], length[cur]);
        REP(i,0,G[cur].size()) {
            lli next = G[cur][i];
            if (next < limit || used[next])
                continue;
            que2.push(next);
            used[next] = true;
        }
    }
    cout << ans_max  - 1 << endl;
}
