from collections import defaultdict as d

def dfs(adj, visited, count, tab, start):
	visited[start-1] = 1
	for v in adj[start]:
		if not visited[v-1]:
			tab[v-1] += count
			dfs(adj, visited, count+1, tab, v)
	return tab		

n, u, v = map(int, input().split())
adj = d(list)
for i in range(n-1):
	a, b = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)
	
takahashi = dfs(adj, [0] * n, 1, [0] * n, u)
aoki = dfs(adj, [0] * n, 1, [0] * n, v)

res = -1
for i in range(n):
	if takahashi[i] <= aoki[i]:
		res = max(res, aoki[i] - 1)

print(res)
