#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);
}

int n;
vector<int> to(100005);
std::vector<int> dist;

void dfs(int V, int d = 0, int P= -1){
	dist[V] = d;
	for(int u: to[V]){
		if(u== v) continue;
		dfs(u,d+1,V);
	}
}


vector<int> calDistance(int P){
	vector<int> dist(n);
	dfs(P);
	return dist;
}



int main(){
	cin >> n;
	int T,A; cin >> T >> A;

	// buh tseguudee to array ruu hiine
	rep(i,n-1){
		int a,b; cin >> a >> b;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	vector<int> distFromA = calDistance(A);
	vector<int> distFromT = calDistance(T);
	int ret = 0;
	rep(i,n){
		if(distFromA[i] < distFromT[i]){
			self_max(ret,distFromT[i]-1);
		}
	}

	cout << ret << endl;
	return 0;
}