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

#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")

const long long maxn = 1e5 + 10;

long long n;
long long U, V;
bool mark[maxn];
long long f[20][maxn];
long long height[maxn];
vector<long long> adj[maxn];
long long dp[maxn], DP[maxn];
long long ans;

void in();
void solve();
void dfs(long long u);
void calcDP(long long u);
void calcf();
long long lca(long long u, long long v);
long long father(long long u, long long t);
void out();

long long main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n >> U >> V;
    U--;
    V--;
    for(long long i = 1; i < n; i++){
        long long u, v;
        cin >> u >> v;
        u--;
        v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    memset(f, -1, sizeof f);
    dfs(0);
    calcDP(0);
    calcf();
}

void solve(){
    long long x = lca(U, V);
    long long disV = height[V] - height[x];
    long long disU = height[U] - height[x];
    if(disV <= disU){
        ans += (disV + disU - 1) / 2;
        U = father(U, (disV + disU - 1) / 2);
        ans += dp[U];
        if((disU + disV) % 2 == 0)
            ans++;
    }
    else{
        ans += (disV + disU - 1) / 2;
        U = father(V, (disV + disU) / 2);
        ans += DP[U];
        if((disU + disV) % 2 == 0)
            ans++;
    }
}

void dfs(long long u){
    mark[u] = 1;
    for(auto v: adj[u]){
        if(!mark[v]){
            f[0][v] = u;
            height[v] = height[u] + 1;
            dfs(v);
            dp[u] = max(dp[v] + 1, dp[u]);
        }
    }
}

void calcDP(long long u){
    mark[u] = 0;
    long long maxim = 0;
    long long secmax = 0;
    if(u != 0)
        maxim = DP[u] + 1;
    for(auto v: adj[u]){
        if(mark[v]){
            if(dp[v] >= maxim){
                secmax = maxim;
                maxim = dp[v];
            }
            else if(dp[v] > secmax)
                secmax = dp[v];
        }
    }
    for(auto v: adj[u]){
        if(mark[v]){
            DP[v] = maxim;
            if(dp[v] == maxim)
                DP[v] = secmax;
            calcDP(v);
        }
    }
}

void calcf(){
    for(long long i = 1; i < 20; i++)
        for(long long j = 0; j < n; j++)
            if(f[i - 1][j] != -1)
                f[i][j] = f[i - 1][f[i - 1][j]];
}

long long lca(long long u, long long v){
    if(height[u] > height[v])
        swap(u, v);
    for(long long i = 19; i >= 0; i--)
        if(f[i][v] != -1 && height[f[i][v]] >= height[u])
            v = f[i][v];
    if(u == v)
        return u;
    for(long long i = 19; i >= 0; i--){
        if(f[i][v] != -1 && f[i][u] != -1 && f[i][v] != f[i][u]){
            v = f[i][v];
            u = f[i][u];
        }
    }
    return f[0][u];
}

long long father(long long u, long long t){
    for(long long i = 19; i >= 0; i--){
        if(((1 << i) & t) != 0){
            u = f[i][u];
        }
    }
    return u;
}

void out(){
    cout << ans;
}
