#1-index
import sys
input = sys.stdin.readline

from collections import deque

N, u, v = map(int, input().split())
G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    A, B = map(int, input().split())
    G[A].append(B)
    G[B].append(A)

queT = deque()
queA = deque()

checkT = [-1] * (N + 1)
checkA = [-1] * (N + 1)

checkT[u] = 0
checkA[v] = 0

queT.append(u)
queA.append(v)
flag = True
while queT or queA: #どちらかが生きているとき
    tmp_lst = []
    while queT:
        tmp = queT.popleft()
        d = checkT[tmp]
        for next_ in G[tmp]:
            if checkT[next_] == -1:
                if checkA[next_] != -1:
                    flag = False
                    turn = True #高橋くんが動くとぶつかる
                    break
                checkT[next_] = d + 1
                tmp_lst.append(next_)
        if not flag:
            break
    if not flag:
        break
    for i in tmp_lst:
        queT.append(i)
    
    tmp_lst = []
    while queA:
        tmp = queA.popleft()
        d = checkA[tmp]
        for next_ in G[tmp]:
            if checkA[next_] == -1:
                if checkT[next_] != -1:
                    flag = False
                    turn = False #青木くんが動くとぶつかる
                    break
                checkA[next_] = d + 1
                tmp_lst.append(next_)
        if not flag:
            break
    if not flag:
        break
    for i in tmp_lst:
        queA.append(i)

# print (checkT)
# print (checkA)
# print (d)
# print (turn)
# print (tmp) #現在の場所
#ここまでで二人がギリギリまで近づく位置と、どちらが動いたらぶつかるかが分かる

ans = 0
check = [-1] * (N + 1)
check[tmp] = 0
stack = [tmp]
while stack:
    tmp1 = stack.pop()
    tmp_d = check[tmp1]
    flag = True
    for next_ in G[tmp1]:
        if check[next_] == -1 and checkA[next_] == -1:
            check[next_] = tmp_d + 1
            stack.append(next_)
            flag = False
    if flag:
        ans = max(ans, tmp_d)

# print (check)

if turn:
    print (d + ans)
else:
    print (d + ans - 1)