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

ans = 0
if u==v:
    print(0)
    exit()

#u〜vの最短経路を求める
r = []
used = [False]*N
def dfs(i,end):
    global r
    used[i] = True
    if i==end:
        r.append(i)
        return True
    for e in E[i]:
        if not used[e]:
            if dfs(e,end):
                r.append(i)
                return True
    return False
dfs(v,u)

ans += (len(r)//2)+(len(r)&1)
v = r[len(r)//2]
u = r[(len(r)//2)-1]

#uから最も遠い頂点までの距離を求める
dmax = 0
used = [False]*N
def dfs2(i,end,d):
    global dmax
    used[i] = True
    if i==end:
        return
    dmax = max(dmax,d)
    for e in E[i]:
        if not used[e]:
            dfs2(e,end,d+1)
dfs2(u,v,0)
ans += dmax - 1

print(ans)