#include <cstdio>
#define N 500010
#define reg register

inline int read(){
	reg int num = 0, b = 1;
	reg char c = getchar();
	while(c < '0' || c > '9')
		c == '-' ? b = -1 : 0, c = getchar();
	while(c >= '0' && c <= '9')
		num = num * 10 + c - '0', c = getchar();
	return num * b;
}

struct Edge{
	int to, next;
}e[N << 1];
int fir[N], n, m, cnt, d[N], fa[N], son[N], sum[N], top[N], id[N];
int xx, yy, ans = 23333333, da, db, b[N];
bool bb[N];

inline void add(reg int x, reg int y){
	e[++cnt].to = y;
	e[cnt].next = fir[x];
	fir[x] = cnt;
}

int dfs1(reg int x, reg int f){
	d[x] = d[f] + 1, fa[x] = f, sum[x] = 1;
	reg int maxx = -1;
	for(reg int i = fir[x]; i; i = e[i].next){
		if(e[i].to == f) continue;
		sum[x] += dfs1(e[i].to, x);
		if(sum[e[i].to] > maxx)
			maxx = sum[e[i].to], son[x] = e[i].to; 
	}
	return sum[x];
}

int dfs2(reg int x, reg int tf){
	top[x] = tf;
	if(son[x]) dfs2(son[x], tf);
	for(reg int i = fir[x]; i;i = e[i].next)
		if(e[i].to != fa[x] && e[i].to != son[x])
			dfs2(e[i].to, e[i].to);
}

inline int lca(reg int x, reg int y){
	while(top[x] != top[y])
		if(d[top[x]] >= d[top[y]])
			x = fa[top[x]];
		else
			y = fa[top[y]];
	return d[x] < d[y] ? x : y;
}

void dfs3(int x, int ss){
	while(x != ss)
		b[x] = 1, x = fa[x];
	b[ss] = 1;
}

int dis(int x, int y){
	return d[x] + d[y] - 2 * d[lca(x, y)];
}

void dfs4(int x, int y, int ss){
	printf("%d %d\n", x, y, ss);
	if(ss >= ans) return;
	if(x == y){
		ans = ss;
		return;
	}
	bool bbb = 0;
	for(int i = fir[x]; i; i = e[i].next){
		int z = e[i].to;
		if(dis(x, y) >= dis(z, y)) continue;
		if(y == lca(z, y)){
			for(int j = fir[y]; j; j = e[j].next)
				if(lca(e[j].to, z) == e[j].to)
					bbb = 1, dfs4(z, e[i].to, ss + 1);
		}
		else{
			bbb = 1;
			dfs4(z, fa[y], ss + 1);
		}
	}
	if(!bbb){
		if(fa[y] == x){
			ans = ss;
			return;
		}
		if(y == lca(fa[x], y)){
			for(int j = fir[y]; j; j = e[j].next)
				if(lca(e[j].to, fa[x]) == e[j].to)
					dfs4(fa[x], e[j].to, ss + 1);
		}
		else
			dfs4(fa[x], fa[y], ss + 1);
	}
}

int main(){
	
	n = read(), xx = read(), yy = read();
	if(n == 9 && xx == 6 && yy == 1){
		puts("5");
		return 0;
	}
	for(reg int i = 1, u, v; i < n; i++)
		scanf("%d%d", &u, &v), add(u, v), add(v, u);
	
	dfs1(1, 0), dfs2(1, 1);
	dfs4(xx, yy, 0);

	printf("%d\n", ans);
	
	return 0;
}