#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> adj[200005];
bool vis[200005];

vector<int> bfs(int u){
	queue<int>q;
	q.push(u);
	memset(vis, false, sizeof(vis));
	vector<int> level(200005);
	while(!q.empty()){
		int x = q.front();
		vis[x] = true;
		q.pop();
		for(auto nei : adj[x]){
			if(!vis[nei]){
				q.push(nei);
				level[nei] = level[x] + 1; 
			}
		}
	}
	return level;
}

signed main(){
	int n, u, v, x, y;
	cin>>n>>u>>v;
	for(int i=0; i<n-1; i++){
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	int ans = -1;
	vector<int> aoki = bfs(v);
	vector<int> tash = bfs(u);
	for(int i=1; i<=n; i++){
		if(aoki[i] > tash[i])
			ans = max(aoki[i]-1, ans);
	}
	cout<<ans;
}