import sys
input = sys.stdin.readline

def main():
    n,u,v = map(int,input().split())

    edges = [[] for _ in range(n)]

    for _ in range(n-1):
        a,b = map(int,input().split())
        edges[a-1].append(b-1)
        edges[b-1].append(a-1)

    stack1 = [u-1]
    stack2 = [v-1]

    dis1 = [-1] * n
    dis2 = [-1] * n
    dis1[u-1] = 0
    dis2[v-1] = 0

    count = 0

    while stack1 or stack2:
        count += 1
        for _ in range(len(stack1)):
            q1 = stack1.pop(0)
            for i in edges[q1]:
                if dis1[i] == -1 and dis2[i] == -1:
                    dis1[i] = count
                    stack1.append(i)

        for _ in range(len(stack2)):
            q2 = stack2.pop(0)
            for i in edges[q2]:
                if dis2[i] == -1:
                    dis2[i] = count
                    stack2.append(i)

    ans = 0
    for i in range(n):
        if dis1[i] != -1:
            ans = max(ans, dis2[i])

    print(ans-1)

if __name__ == '__main__':
    main()
