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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,x,y;
	cin >> n >> x >> y;
	x--,y--;
	vector<vector<int>> ad(n);
	for(int i=1;i<n;i++){
		int a,b;
		cin >> a >> b;
		a--,b--;
		ad[a].push_back(b);
		ad[b].push_back(a);
	}
	
	vector<int> dist(n);
	function<void(int,int,int)> dfs=[&](int cur,int par,int di){
		for(int ch:ad[cur]){
			if(ch==par) continue;
			dfs(ch,cur,di+1);
		}
		dist[cur]=di;
	};
	dfs(y,-1,0);
	
	vector<int> dist2(n);
	function<void(int,int,int)> dfs2=[&](int cur,int par,int di){
		for(int ch:ad[cur]){
			if(ch==par) continue;
			dfs2(ch,cur,di+1);
		}
		dist2[cur]=di;
	};
	dfs2(x,-1,0);
	int res=0;
	for(int i=0;i<n;i++){
		if(dist[i]<dist2[i]) continue;
		res=max(res,dist[i]);
	}
	cout << (res-1) << "\n";
	return 0;
}
