#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const ll INF = LLONG_MAX/3;

/*-----Library-----*/

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 UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
//コンビネーション
/*
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 */
/*-----Library-----*/
const int MOD=1234567;
int raa[110000],rat[110000];
vector<int> es[110000];
vector<int> memo;
void bfsa(int s){
	raa[s]=1;
	queue<P> task;
	rep(i,es[s].size())task.push(P(s,es[s][i]));
	while(!task.empty()){
		P t=task.front(); task.pop();
		raa[t.second]=raa[t.first]+1;
		int c=0;
		rep(i,es[t.second].size()){
			c++;
			if(raa[es[t.second][i]]==-1)task.push(P(t.second,es[t.second][i]));
		}
		if(c==1)memo.push_back(t.second);
	}
}
void bfst(int s){
	rat[s]=1;
	queue<P> task;
	rep(i,es[s].size())task.push(P(s,es[s][i]));
	while(!task.empty()){
		P t=task.front(); task.pop();
		rat[t.second]=rat[t.first]+1;
		int c=0;
		rep(i,es[t.second].size()){
			c++;
			if(rat[es[t.second][i]]==-1)task.push(P(t.second,es[t.second][i]));
		}
		if(c==1)memo.push_back(t.second);
	}
}

signed main(){
	int n,u,v;
	cin>>n>>u>>v;
	u--;
	v--;
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		es[a-1].push_back(b-1);
		es[b-1].push_back(a-1);
	}
	rep(i,n)raa[i]=-1;
	bfsa(v);
	rep(i,n)rat[i]=-1;
	bfst(u);
	int ans=0;
	rep(i,n){
		if(raa[i]<=rat[i])continue;
		chmax(ans,rat[i]-1+raa[i]-rat[i]-1);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 10736