n,ta,ao = map(int,input().split())
ta,ao = ta-1,ao-1
tree_list = [[] for i in range(n)]
ans = 0
for i in range(n-1):
	a,b = map(int,input().split())
	a,b = a-1,b-1
	tree_list[a].append(b)
	tree_list[b].append(a)

def find_tree(tree:list,start:int) -> list:
	depth = [-1]*n
	stack = [tree[start]]
	depth[start] = 0
	dep = 1
	while stack:
		S = stack
		stack = []
		for s in S:
			for ttt in s:
				if depth[ttt] != -1:
					continue
				elif ttt == ao:
					depth[ttt] = 0
					continue
				depth[ttt] = dep
				stack.append(tree[ttt])
		dep += 1
	return depth

taka_tree = find_tree(tree_list,ta)
aoki_tree = find_tree(tree_list,ao)
for t,a in zip(taka_tree,aoki_tree):
	if t < a:
		ans = max(ans,a-1)

print(ans)