#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

struct RMinQ{
private:
    int N;
    vector<long long> node, lazy;
    vector<bool> lazyFlg;
    long long DEFAULT;
public:
    void init(int n, long long def=9223372036854775807LL){
        DEFAULT = def;
        node.clear();
        lazy.clear();
        lazyFlg.clear();
        N = 1;
        while(N < n) N = (N<<1);
        for(int i=0; i<2*N-1; i++){
            node.push_back(DEFAULT);
            lazy.push_back(0LL);
            lazyFlg.push_back(false);
        }
    }
    void eval(int k, int l, int r){
        if(lazyFlg[k]){
            node[k] = lazy[k];
            if(r-l > 1){
                lazy[(k<<1)+1] = lazy[k];
                lazyFlg[(k<<1)+1] = true;
                lazy[(k<<1)+2] = lazy[k];
                lazyFlg[(k<<1)+2] = true;
            }
            lazy[k] = 0LL;
            lazyFlg[k] = false;
        }
        else{
            node[k] += lazy[k];
            if(r-l > 1){
                lazy[(k<<1)+1] += lazy[k];
                lazy[(k<<1)+2] += lazy[k];
            }
            lazy[k] = 0LL;
        }
    }
    void update(int a, long long x){
        update(a, a+1, x);
    }
    void update(int a, int b, long long x, int k=0, int l=0, int r=-1){
        if(r == -1) r = N;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b){
            lazy[k] = x;
            lazyFlg[k] = true;
            eval(k, l, r);
        }
        else{
            update(a, b, x, (k<<1)+1, l, (l+r)>>1);
            update(a, b, x, (k<<1)+2, (l+r)>>1, r);
            node[k] = std::min(node[(k<<1)+1], node[(k<<1)+2]);
        }
    }
    void add(int a, long long x){
        add(a, a+1, x);
    }
    void add(int a, int b, long long x, int k=0, int l=0, int r=-1){
        if(r == -1) r = N;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b){
            lazy[k] += x;
            eval(k, l, r);
        }
        else{
            add(a, b, x, (k<<1)+1, l, (l+r)>>1);
            add(a, b, x, (k<<1)+2, (l+r)>>1, r);
            node[k] = std::min(node[(k<<1)+1], node[(k<<1)+2]);
        }
    }
    long long min(int a, int b, int k=0, int l=0, int r=-1){
        if(r == -1) r = N;
        if(b <= l || r <= a) return 9223372036854775807LL;
        eval(k, l, r);
        if(a <= l && r <= b) return node[k];
        return std::min(min(a, b, (k<<1)+1, l, (l+r)>>1), min(a, b, (k<<1)+2, (l+r)>>1, r));
    }
    long long m;
    int find(int a, int b, int k=0, int l=0, int r=-1){
        if(r == -1){
            m = min(a, b);
            r = N;
        }
        if(r <= a || b <= l) return INT_MAX;
        if(r-l == 1){
            if(node[k] == m) return l;
            else return INT_MAX;
        }
        if(a <= l && r <= b){
            int valueL = min(a, b, (k<<1)+1, l, (l+r)/2);
            int valueR = min(a, b, (k<<1)+2, (l+r)/2, r);
            if(valueL == m) return find(a, b, (k<<1)+1, l, (l+r)>>1);
            if(valueR == m) return find(a, b, (k<<1)+2, (l+r)>>1, r);
            return INT_MAX;
        }
        return std::min(find(a, b, (k<<1)+1, l, (l+r)>>1), find(a, b, (k<<1)+2, (l+r)>>1, r));
    }
};

// 高橋君は青木君から一番遠い葉に移動する，ただし途中で鉢合わせないように注意
// 青木君はひたすら近づく努力をすればいい
// 偶奇に注意

int N, u, v;
vector<int> e[100000];

int pre[100000];
int r[100000];
int depth[100000];
int cnt = 0;
vector<int> EulerTour;
int pos[100000];
void dfs(int n, int p, int d){
    pre[n] = cnt;
    r[cnt] = n;
    cnt++;
    depth[n] = d;
    EulerTour.pb(pre[n]);
    rep(i, e[n].size()){
        if(e[n][i] == p) continue;
        dfs(e[n][i], n, d+1);
        EulerTour.pb(pre[n]);
    }
    pos[n] = EulerTour.size()-1;
}

RMinQ rmq;
int lca(int a, int b){
    int x = pos[a];
    int y = pos[b];
    if(x > y) swap(x, y);
    return r[rmq.min(x, y+1)];
}

int dist(int a, int b){
    return depth[a]+depth[b]-2*depth[lca(a, b)];
}

signed main(){
    cin >> N >> u >> v;
    u--; v--;
    rep(i, N-1){
        int A, B;
        cin >> A >> B;
        A--; B--;
        e[A].pb(B);
        e[B].pb(A);
    }

    rep(i, N){
        if(e[i].size() > 1){
            dfs(i, -1, 0);
            break;
        }
    }
    rmq.init(EulerTour.size());
    rep(i, EulerTour.size()) rmq.update(i, EulerTour[i]);

    int ans = 0;
    rep(i, N){
        int x = dist(i, u);
        int y = dist(i, v);
        if(x >= y) continue;
        if((x+y)%2 == 0) ans = max(ans, dist(i, v)-1);
        else ans = max(ans, dist(i, v)-1);
    }
    cout << ans << endl;

    /*rep(i, N){
        rep(j, N) cout << lca(i, j)+1 << " ";
        cout << endl;
    }*/
}

Measured memory_bytes: 24868