import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)


n, u, v = map(int, input().split())
u, v = u-1, v-1
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append(b)
    G[b].append(a)

is_leaf = [0]*n
def dfs(c,p,d):
    dep[c] = d
    f = True
    for to in G[c]:
        if to != p:
            dfs(to, c, d+1)
            f = False
    if f:
        is_leaf[c] = 1


dep = [0]*n
dfs(v, -1, 0)
a = dep[:]
leaf = is_leaf[:]
dfs(u, -1, 0)
b = dep

ans = 0
for i in range(n):
    if not leaf[i]:
        continue
    if b[i] >= a[i]:
        continue
    tmp = 0
    d = b[i]
    if d != 0:
        tmp = 2*d
        aoki = d
    else:
        aoki = 0
    tak = a[i]
    m = tak-aoki
    if m%2==1:
        tmp += 2*m -1
    else:
        tmp += 2*(m-1)
    ans = max(ans, tmp)
print(ans//2)