def f():
    n, u, v = [int(s) for s in input().split()]
    u -= 1
    v -= 1
    neibors = [[] for i in range(n)]
    for i in range(n-1):
        a, b = [int(s)-1 for s in input().split()]
        neibors[a].append(b)
        neibors[b].append(a)
    if u == v:
        return 0

    visited = [0]*n
    thisLayer = [u]
    visited[u] = 1
    children = [set() for i in range(n)]
    father = [None]*n

    while thisLayer:
        nextLayer = []
        for node in thisLayer:
            for nb in neibors[node]:
                if not visited[nb]:
                    children[node].add(nb)
                    father[nb] = node
                    nextLayer.append(nb)
                    visited[nb] = 1
        thisLayer = nextLayer
    # print(children)
    # print(father)
    def getHight(root):
        thisLayer = [root]
        h = 0
        while thisLayer:
            h += 1
            nextLayer = []
            for node in thisLayer:
                for child in children[node]:
                    nextLayer.append(child)
            thisLayer = nextLayer
        return h

    node = v
    distance = 0
    while node != u:
        node =father[node]
        distance += 1

    if len(children[u]) <= 1 and distance <=2 :
        return distance-1

    node = v
    step = 0
    half = distance//2
    while step < half:
        node = father[node]
        step += 1
    ans = 0
    while node != u:
        children[father[node]].discard(node) # cutoff
        node = father[node]
        h = getHight(node)
        ans = max(step + h, ans)
        step += 1
    return ans - distance%2

print(f())