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

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll u; cin >> u; u--;
    ll v; cin >> v; v--;
    vector <vector<ll>> as(n, vector<ll>());
    REP(i, n){
        ll a; cin >> a; a--;
        ll b; cin >> b; b--;
        as[b].push_back(a);
        as[a].push_back(b);
    }
    vector <ll> kyori1(n, -1);
    queue <ll> q;
    q.push(u);
    kyori1[u] = 0;
    while (!q.empty()){
        ll now = q.front();
        ll k = kyori1[now];
        q.pop();
        for(auto next: as[now]){
            if (kyori1[next] > -1){
                continue;
            }
            kyori1[next] = k + 1;
            q.push(next);
        }
    }

    vector <ll> kyori2(n, -1);
    q.push(v);
    kyori2[v] = 0;
    while (!q.empty()){
        ll now = q.front();
        ll k = kyori2[now];
        q.pop();
        for(auto next: as[now]){
            if (kyori2[next] > -1){
                continue;
            }
            kyori2[next] = k + 1;
            q.push(next);
        }
    }
    ll ans = 0;
    REP(i, n){
        if (kyori1[i] <= kyori2[i]){
            ans = max(ans, kyori2[i]);
        }
    }
    cout << ans-1 << endl;
    return 0;
}