#include<bits/stdc++.h>
using namespace std;
const int MN = 1e5+3;
bool insub[MN];
int lca[MN], d[MN],t;
vector<int> adj[MN];
int ans=0;
void ree (int cur, int p = -1) {
	for (int i : adj[cur]) if (i != p) {
		d[i] = d[cur] + 1;
		ree(i,cur);
		insub[cur] |= insub[i];
	}
}
void dfs (int cur, int p = -1, int l = -1) {
	bool leaf = 1;
	for (int i : adj[cur]) if (i != p) {
		leaf = 0;
		if (insub[i]) dfs(i,cur);
		else dfs(i,cur,~l?l:cur);  
	}
	if (cur == t) l = t;
	if (leaf && d[t]-d[l] < d[l]) {
		int arrival = d[t]+d[cur]-(d[l]<<1);
		ans = max(ans,d[cur]-1);
	}
}
int main () {
	int n,a;
	scanf ("%d %d %d",&n,&t,&a);
	for (int i = 1; i < n; i++) {
		int b,c;
		scanf ("%d %d",&b,&c);
		adj[b].push_back(c);
		adj[c].push_back(b);
	}
	insub[t] = 1;
	ree(a);
	dfs(a);
	printf ("%d\n",ans);
	return 0;
}