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

def getDist(adjList, vSt, vEn):
    numV = len(adjList)
    costs = [-1] * numV
    costs[vSt] = cost = 0
    vs = [vSt]
    while vs:
        cost += 1
        v2s = []
        for v in vs:
            for v2 in adjList[v]:
                if costs[v2] == -1:
                    costs[v2] = cost
                    v2s.append(v2)
        vs = v2s
    return costs[vEn]

# 初期状態での2人の距離
dist0 = getDist(adjL, u, v)
ans1 = dist0 - 1

def setIsOKs(adjList, vSt, dist):
    numV = len(adjList)
    costs = [-1] * numV
    costs[vSt] = cost = 0
    vs = [vSt]
    isOKs[vSt] = False
    while vs:
        cost += 1
        v2s = []
        for v in vs:
            for v2 in adjList[v]:
                if costs[v2] == -1:
                    costs[v2] = cost
                    isOKs[v2] = False
                    v2s.append(v2)
        vs = v2s
        if cost >= dist:
            break
    return

isOKs = [True] * N
setIsOKs(adjL, v, dist0//2)

def getDist2(adjList, vSt):
    numV = len(adjList)
    costs = [-1] * numV
    costs[vSt] = cost = 0
    vs = [vSt]
    while vs:
        cost += 1
        v2s = []
        for v in vs:
            for v2 in adjList[v]:
                if not isOKs[v2]: continue
                if costs[v2] == -1:
                    costs[v2] = cost
                    v2s.append(v2)
        vs = v2s

    maxC = cost-1
    vMaxC = costs.index(maxC)
    return vMaxC, maxC

# 最も遠い頂点への高橋くんからの距離
vMaxC, distT = getDist2(adjL, u)

# 最も遠い頂点への青木くんからの距離
distA = getDist(adjL, v, vMaxC)

if distT == 0:
    ans2 = 0
else:
    ans2 = distT + distA-distT-1

print(max(ans1, ans2))
