#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 


struct edge{
    ll to,cost;
};
ll n;
vector<edge>  G[100010];
vll prever;
ll d[100010];

void  dijkstra(ll s){
    priority_queue<pll,vector<pll>,greater<pll>> que;
    fill(d,d+n,LLINF);
    d[s]=0;
    que.push(pll(0,s));
    prever = vll(n,-1);

    while(!que.empty()){
        pll p=que.top();que.pop();
        ll v=p.second;
        if(d[v]<p.first) continue;
        rep(i,(ll)G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                prever[e.to] = v;
                que.push(pii(d[e.to],e.to));
            }
        }
    } 
}

vll get_path(ll t){
    vll path;
    for(; t != -1;t=prever[t]){
        path.push_back(t);
    }

    reverse(path.begin(), path.end());
    return path;
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    ll u,v;
    cin>>n>>u>>v;
    u--;v--;
    rep(i,n-1){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb({b,1});
        G[b].pb({a,1});
    }
    dijkstra(v);
    vll path=get_path(u);
    ll m=d[u];
    rep(i,(ll)(path.size()+1)/2){
        G[path[i]].clear();
        G[path[i]].pb({path[i+1],1});
    }
    dijkstra(v);
    ll ans=0;
    if(m==1){
        cout<<0<<endl;
        return 0;
    }
    rep(i,n){
        if(d[i]!=LLINF){
            if(m%2==0){
                chmax(ans,max(1ll,d[i]-1));
                // cout<<i<<" "<<d[i]<<endl;

            }
            else{
                chmax(ans,max(1ll,d[i]-1));
                // cout<<i<<" "<<d[i]<<endl;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10624