#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<ll> node;
};

ll CA[100005];
ll CT[100005];
Vertex V[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, A, T;
    cin >> N >> T >> A;
    T--;
    A--;
    REP(i, N) {
        CT[i] = CA[i] = INF;
    }
    REP(i, N - 1) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        V[a].node.push_back(b);
        V[b].node.push_back(a);
    }

    {
        queue<pll> q;
        q.push(pll(A, 0));
        CA[A] = 0;
        while (!q.empty()) {
            pll t = q.front();
            q.pop();
            ll cost = t.second + 1;
            for (auto n : V[t.first].node) {
                if (CA[n] <= cost)
                    continue;
                CA[n] = cost;
                q.push(pll(n, cost));
            }
        }
    }
    {
        queue<pll> q;
        q.push(pll(T, 0));
        CT[T] = 0;
        while (!q.empty()) {
            pll t = q.front();
            q.pop();
            ll cost = t.second + 1;
            for (auto n: V[t.first].node) {
                if (CT[n] <= cost)
                    continue;
                CT[n] = cost;
                q.push(pll(n, cost));
            }
        }
    }

    ll ans = 0;
    REP(i, N) {
        if (CA[i] >= CT[i])
            ans = std::max(ans, CA[i] - 1);
    }
    cout << ans << endl;
    return 0;
}
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 1e5 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

ll n,i,mx[N],p,q,maxx,cur;
LL a[N],b[N];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    q = n + 1; a[q].sc = inf;
    cin>>n;
    for (i = 1;i <= n;i++){
        cin>>a[i].fs>>a[i].sc;
        a[i].sc++;
        maxx = max(maxx,a[i].sc - a[i].fs);
        if (a[i].fs > a[p].fs) p = i;
        if (a[i].sc < a[q].sc) q = i;
    }
    p = a[p].fs; q = a[q].sc;
    ll ans = maxx + max(0ll,q - p);
    for (i = 1;i <= n;i++){
        b[i].fs = max(0ll,a[i].sc - p);
        b[i].sc = q - a[i].fs;
    }
    sort(b + 1,b + n + 1);
    for (i = n;i >= 1;i--) mx[i] = max(mx[i + 1],b[i].sc);
    cur = b[1].sc;
    for (i = 1;i <= n;i++){
        if (i == 1) ans = max(ans,b[i].fs + mx[i + 1]);
        else ans = max(ans,b[i].fs + max(cur,mx[i + 1]));
        cur = min(cur,b[i].sc);
    }
    cout<<ans;
}
