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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

vvi g ;
vi level ;
vi p ;

void dfs ( int node , int parent = -1 )
{
    if ( parent != -1 )
        level[node] = level[parent] + 1 ;

    if ( parent != -1 ) { p[node] = parent ; }

    for ( auto i : g[node] )
    {
        if ( i == parent ) C ;
        dfs ( i , node ) ;
    }
}

int max_level = -1 ;

void dfs2 ( int node , int parent = -1 )
{
    max_level = max ( max_level , level[node] ) ;

    for ( auto i : g[node] )
    {
        if ( i == parent ) C ;
        if ( i == p[node] ) C ;

        dfs2 ( i , node ) ;
    }
}

void solve ( int test_case )
{
    int n , node , root ;
    cin >> n >> node >> root ;

    node -- ; root-- ;

    g.resize ( n ) ;
    p.resize ( n ) ;

    for ( int i=0 ; i < n-1 ; i ++ )
    {
        int a , b ;
        cin >> a >> b ;

        a -- ;
        b -- ;

        g[a].pb ( b ) ;
        g[b].pb ( a ) ;
    }

    level.resize ( n ) ;
    dfs ( root ) ;

    int dis = level[node] ;
    if ( dis % 2 == 0 )
        dis -- ;

    dis >>= 1 ;
    int ans = dis ; // up-level movement

    int oki_current = dis ;
    int tak_current = node ;

    for ( int i=0 ; i < dis ; i ++ )
    {
        tak_current = p[tak_current] ;
    }

    dfs2 ( tak_current ) ; // max_level !

    if ( max_level != -1 )
    {
        dis = max_level - level[tak_current] ;
        ans += dis ;
    }

    oki_current += dis ;
    tak_current = max_level ;

    int c = 0 ;
    while ( oki_current != tak_current )
    {
        if ( c == 0 ) tak_current -- ;
        else tak_current ++ ;

        if ( tak_current == oki_current )
            break ;

        oki_current ++ ;
        ans ++ ;
        c ^= 1 ;
    }

    cout << ans ; line
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 10368