import sys
from collections import deque

input = sys.stdin.readline

N, u, v = map(int, input().split())
u -= 1
v -= 1
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

u_dist = [-1 for _ in range(N)]
v_dist = [-1 for _ in range(N)]

u_q = set([u])
v_q = set([v])

ans = -1
count = 0
visited = set()
while u_q and v_q:
    u_next = set()
    v_next = set()
    # print("count", count)
    for u_p in u_q:
        if u_p in u_next:
            continue
        for np in edges[u_p]:
            if np in v_q:
                # print("touched!")
                ans = count
            else:
                u_next.add(np)
    if not u_next:
        break
    count += 1
    for v_p in v_q:
        if v_p in visited:
            continue
        visited.add(v_p)
        for np in edges[v_p]:
            v_next.add(np)
            if np in u_next:
                # print("touched!!!")
                ans = count
                u_next.remove(np)

            
    u_q = u_next
    v_q = v_next
    # print(u_q)
    # print(v_q)

print(ans)