#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;


int main() {
    int n, u, v; cin >> n >> u >> v;
    vector<vector<int>> g(n+1);
    rep(i, n-1){
        int a, b; cin >> a >> b;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
    }

    vector<int> distU(n+1, -1);
    vector<int> distV(n+1, -1);
    queue<int> qu, qv;
    qu.push(u);
    qv.push(v);
    
    distU.at(u) = 0;
    distV.at(v) = 0;

    while(!qu.empty()){
        int t = qu.front();
        qu.pop();

        for(auto a:g.at(t)){
            if(distU.at(a)!=-1) continue;
            distU.at(a) = distU.at(t) + 1;
            qu.push(a);
        }
    }

    while(!qv.empty()){
        int t = qv.front();
        qv.pop();

        for(auto a:g.at(t)){
            if(distV.at(a)!=-1) continue;
            distV.at(a) = distV.at(t) + 1;
            qv.push(a);
        }
    }

    int fart = v;
    ll dist = 0;
    for(int i=1; i<=n; i++){
        if(distU.at(i)<distV.at(i)){
            if(dist<distV.at(i)){
                dist = distV.at(i);
                fart = i;
            }
        }
    }

    dump(fart);
    if(fart==v){
        cout << 0 << endl;
    }
    else{
        cout << distV.at(fart) - 1 << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;

ll N, u, v; 
vector<vector<ll>> G;
vector<ll> du, dv;

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> u >> v;
	--u, --v;

	G.resize(N);
	du.assign(N, -1);
	dv.assign(N, -1);

	REP(i, N-1)
	{
		ll a, b; cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	queue<ll> que;
	que.push(v);
	dv[v] = 0;

	while (que.size())
	{
		ll now = que.front();
		que.pop();

		for (auto &nv : G[now])
		{
			if (dv[nv] != -1) continue;
			dv[nv] = dv[now] + 1;
			que.push(nv);
		}
	}

	que.push(u);
	du[u] = 0;

	while (que.size())
	{
		ll now = que.front();
		que.pop();

		for (auto &nv : G[now])
		{
			if (du[nv] != -1) continue;
			du[nv] = du[now] + 1;
			que.push(nv);
		}
	}

	ll res{0};
	REP(n, N)
	{
		if (du[n] < dv[n])
		{
			res = max(res, dv[n] - 1);
		}
	}

	std::cout << res<< std::endl;	
	return 0;
}
