#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n;
    vi ta(2);
    cin>>n>>ta[0]>>ta[1];
    ta[0]--;
    ta[1]--;

    vvi to(n);
    int a,b;
    rep(i,n-1){
        cin>>a>>b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    vvi dis(2,vi(n,100000));

    rep(i,2){
        queue<int> que;
        que.push(ta[i]);
        dis[i][ta[i]]=0;
        while(!que.empty()){
            int p=que.front();que.pop();
            rep(j,to[p].size()){
                if(dis[i][to[p][j]]!=100000)continue;
                dis[i][to[p][j]]=dis[i][p]+1;
                que.push(to[p][j]);
            }
        }
    }

    //xxx
    {
        int ans=0;
        rep(i,n){
            if(dis[0][i]<dis[1][i])continue;
            cmax(ans,dis[0][i]+((dis[0][i]-dis[1][i])/2));
        }
    }


    cout<<ans<<"\n";

    return 0;

}

