#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 ;

int n , tak_curr , root ;

vi level ;
vi p ;
vvi g ;

void read()
{
    cin >> n >> tak_curr >> root ;

    g.resize ( n ) ;
    tak_curr -- ; root -- ;

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

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

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

    p[node] = parent ;
    for ( int j : g[node] )
    {
        if ( j == parent ) C ;
        dfs ( j , node ) ;
    }
}

void assign_levels ()
{
    level.resize ( n ) ;
    p.resize ( n ) ;

    dfs ( root ) ;
}

void find_new_position_of_takahashi( int dis )
{
    for ( int i=0 ; i < dis ; i ++ )
        tak_curr = p[tak_curr] ; // climb up dis levels
}

int max_level = -1 ;

void find_max_level_in_new_subtree_of_tak_curr( int node , int parent = -1 )  // This is a dfs
{
    max_level = max ( max_level , level[node] ) ;

    for ( int j : g[node] )
    {
        if ( j == parent ) C ;
        if ( j == p[node] ) C ;

        find_max_level_in_new_subtree_of_tak_curr ( j , node ) ;
    }
}

void solve ( int test_case )
{
    read() ;
    assign_levels() ;

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

    dis >>= 1 ;
    int ans = dis ;
    int oki_level = dis ;

    find_new_position_of_takahashi( dis ) ; // by climbing up
    find_max_level_in_new_subtree_of_tak_curr( tak_curr , -1 ) ;

    dis = max_level - level[tak_curr] ;

    int tak_level = max_level ;
    oki_level += dis ;
    ans += dis ;

    // now since oki is parent ( was root ) ; hence we can say that oki and takahashi are cuurently always in
    // the same subtree.

    // and hence ; we just need to find the time taken by oki to make levels of oki and takahashi same !

    int c = 0 ;
    while ( tak_level != oki_level )
    {
        if ( c == 0 ) tak_level -- ;
        else tak_level ++ ;

        if ( tak_level == oki_level )
            break ;

        ans ++ ;
        oki_level ++ ;

        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