#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int n;
vector<vector<int>> tree;
vector<int> d1,d2;

void dfs1(int s, int d = 0, int p = -1){
	d1[s] = d;
	rep(i,tree[s].size()){
		if(tree[s][i] == p) continue;
		dfs1(tree[s][i] , d+1, s);
	}
}

void dfs2(int s, int d = 0, int p = -1){
	d2[s] = d;
	rep(i,tree[s].size()){
		if(tree[s][i] == p) continue;
		dfs2(tree[s][i] , d+1, s);
	}
}

int main(){
	int u,v;
	cin >> n >> u >> v;
	tree.resize(n);
	int a,b;
	rep(i,n-1){
		cin >> a >> b;
		a--; b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	d1.resize(n);
	dfs1(u-1);
	d2.resize(n);
	dfs2(v-1);
	int mx(0);
	rep(i,n){
		if(d1[i] < d2[i] && mx <= d2[i]){
			mx = d2[i];
		}
	}
	cout << mx-1 << endl;
	return 0;
}