from collections import deque

# append(i), popleft()
N, u, v = map(int, input().split())
u, v = u - 1, v - 1
graph = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    graph[a].append(b)
    graph[b].append(a)
dis = [-1 for i in range(N)]
que = deque()
que.append(v)
dis[v] = 0
while que:
    here = que.popleft()
    for next in graph[here]:
        if dis[next] != -1:
            continue
        dis[next] = dis[here] + 1
        que.append(next)
print(dis[u])
