/*input
9 6 1
1 2
2 3
3 4
4 5
5 6
4 7
7 8
8 9
*/
/**
    Author: Kristopher Paul
    Date Created: 21-12-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

//Uncomment for File I/O
/*
#define cin fin
#define cout fout

ifstream fin("cowmbat.in");
ofstream fout("cowmbat.out");
*/

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

vector<int> adj[100005];
int dep[100005];
int par[100005][20];

void dfs(int cv,int p,int d){
    dep[cv] = d;
    FOR(i,0,adj[cv].size()){
        if(adj[cv][i] != p){
            par[adj[cv][i]][0] = cv;
            dfs(adj[cv][i],cv,d+1);
        }
    }
}

int lca(int u,int v){
    if(dep[u] > dep[v]){
        swap(u,v);
    }
    FORD(i,19,0){
        if(dep[u]+(1<<i) <= dep[v]){
            v = par[v][i];
        }
    }
    if(u == v){
        return u;
    }
    FORD(i,19,0){
        if(par[u][i] == par[v][i]){
            continue;
        }
        u = par[u][i];
        v = par[v][i];
    }
    return par[u][0];
}

void solve(){
    int n,u,v;
    cin >> n >> u >> v;
    FOR(i,0,n-1){
        int a,b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(v,0,0);
    par[v][0] = 1;
    FOR(j,1,20){
        FOR(i,1,n+1){
            par[i][j] = par[par[i][j-1]][j-1];
        }
    }
    int mn = 0;
    FOR(i,1,n+1){
        if(i == v){
            continue;
        }
        int c = 0;
        int mid = lca(i,u);
        int mu = dep[u]-dep[mid];
        int mv = dep[mid];
        if(mv < mu){
            remax(mn,mv);
        }else if(mv == mu){
            remax(mn,mv);
        }else{
            mu += dep[i]-dep[mid];
            mv += dep[i]-dep[mid];
            remax(mn,mv-1);
        }
    }
    cout << mn << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 27392