from collections import deque
from heapq import heappop, heappush
from collections import defaultdict
N, u, v = list(map(int, input().split()))
u = u - 1
v = v - 1
T = defaultdict(list)

lenList = [-1] * N

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


q = deque()
q.append(u)

while q:
    i = q.popleft()
    for t in T[i]:
        if lenList[t] == -1:
            lenList[t] = lenList[i] + 1
            q.append(t)


shortest = lenList[v]


maxLen = 0
lenList2 = [-1] * N

for l in lenList:
    shortest2 = shortest // 2
    if shortest2 == l:
        q.append(l)
        lenList2[l] = 0

while q:
    i = q.popleft()
    for t in T[i]:
        if lenList2[t] == -1 and t != v:
            tmp = lenList2[i] + 1
            lenList2[t] = tmp
            if maxLen < tmp:
                maxLen = tmp
            q.append(t)


if shortest % 2 == 0:
    print(max(0, shortest//2 + maxLen-1))
else:
    print(shortest//2 + maxLen)
