// Author : @hello_hell
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <memory.h>
#include <cassert>
#define FAST_INPUT_OUTPUT









#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vvi vector<vector<int>>
#define viil vector<vector<long long>>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define mci map<char , int >
#define mcl map<char , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(i,x) for(auto i=0 ; i<x; ++i)
#define repa(i,a,b) for(auto i=a; i<b; ++i)
#define repe(i,x) for(auto i=0; i<=x; ++i)
#define repea(i,a,b) for(auto i=a;i<=b;++i)
#define ef else if
#define wh while
#define el else
#define ivar(x) int x; cin>>x
#define lvar(x) bint x; cin>>x
#define svar(x) string x; cin>>x
#define cvar(x) char x; cin>>x
#define fvar(x) float x; cin>>x
#define dvar(x) double x; cin>>x
#define endl '\n'
using namespace std;
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT
vector<vector<int>>graph;
vi dis;
vi dis1;
void dfs(int current,int parent,bool &ok,int dist){
    if(ok){
        dis[current]=dist;
    }else{
        dis1[current]=dist;
    }
    for(auto &itr:graph[current]){
        if(itr==parent)continue;
        dfs(itr,current,ok,dist+1);
    }
}
auto SOLUTION_FUNCTION(void)->void{
    // your solution goes here 
    ivar(n);graph.resize(n+1);dis.resize(n+1,INT_MAX);dis1.resize(n+1,INT_MAX);
    ivar(t);ivar(a);
    rep(i,n-1){
        ivar(u);ivar(v);
        graph[u].eb(v);
        graph[v].eb(u);
    }
    bool on=true;
    dfs(a,-1,on,0);
    on = false;
    dfs(t,-1,on,0);
    int ans = 0;
    rep(i,n){
        if(dis[i+1]>dis1[i+1]){
            ans = max(ans,dis[i+1]);
        }
    }
    cout<<ans-1<<endl;
    return ;
}

int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
    freopen("error","w",stderr);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

Measured memory_bytes: 11648