#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
#define INF 2147483647
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}
void self_min(int &a,int b){
	a = min(a,b);
}
vector<int> dist;
void dfs(int v,int d = 0 ; int p = -1){
	dist[v] = d;
	for(int u: v){
		if (u == v) continue;
		dfs(u,d+1,v);
	}
}

vector<int> distances(int p){
	vector<int> dist(n);
	dfs(p);
	return dist;
}

int n;
vector<int> to(100005);
int main(){
	cin >> n;
	int T,A; cin >> T >> A;
	rep(i,n-1){
		int a,b; cin >> a >> b;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	vector<int> distA = distances(A);
	vector<int> distT = distances(T);

	int ret = 0;
	rep(i,n){
		if(distA[i] < distT[i]){
			self_max(ret, distT[i]);
		}
	}
	cout << ret -1 << endl;

	return 0;
}