#%%

n, u, v = list(map(int, input().split()))

u, v = u-1, v-1

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

for i in range(n-1):

    a, b = [int(x)-1 for x in input().split()]

    reach[a].append(b)

    reach[b].append(a)



def x_route(x, reach):

    x_route = [[-1, -1] for _ in range(n)]

    check = [0] * n

    stack = [x]

    check[x] = 1

    x_route[x] = [-1, 0]

    while len(stack) > 0:

        tmp = stack.pop(-1)

        tmp_list = reach[tmp]

        for i in tmp_list:

            if check[i] == 1:

                pass

            else:

                stack.append(i)

                check[i] = 1

                x_route[i] = [tmp, x_route[tmp][1]+1] 

    return x_route



a_route = x_route(v, reach)

t_route = x_route(u, reach)

ans = 0

for i in range(len(a_route)):

    if t_route[i][1] < a_route[i][1]:

        ans = max(ans, a_route[i][1]-1)



print(ans)
n, u, v = list(map(int, input().split()))

u, v = u-1, v-1

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

for i in range(n-1):

    a, b = [int(x)-1 for x in input().split()]

    reach[a].append(b)

    reach[b].append(a)



def x_route(x, reach):

    x_route = [-1] * n

    check = [0] * n

    stack = [x]

    check[x] = 1

    x_route[x] = 0

    while len(stack) > 0:

        tmp = stack.pop(-1)

        tmp_list = reach[tmp]

        for i in tmp_list:

            if check[i] != 1:

                stack.append(i)

                check[i] = 1

                x_route[i] = x_route[tmp]+1

    return x_route



a_route = x_route(v, reach)

t_route = x_route(u, reach)

ans = 0

for i in range(len(a_route)):

    if t_route[i] < a_route[i]:

        ans = max(ans, a_route[i]-1)



print(ans)
#%%
n, u, v = list(map(int, input().split()))
u, v = u - 1, v - 1
reach = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = [int(x) - 1 for x in input().split()]
    reach[a].append(b)
    reach[b].append(a)


def x_route(x, reach):
    x_route = [[-1, -1] for _ in range(n)]
    check = [0] * n
    stack = [x]
    check[x] = 1
    x_route[x] = [-1, 0]
    while len(stack) > 0:
        tmp = stack.pop(-1)
        tmp_list = reach[tmp]
        for i in tmp_list:
            if check[i] == 1:
                pass
            else:
                stack.append(i)
                check[i] = 1
                x_route[i] = [tmp, x_route[tmp][1] + 1]
    return x_route


a_route = x_route(v, reach)
t_route = x_route(u, reach)
ans = 0
for i in range(len(a_route)):
    if t_route[i][1] < a_route[i][1]:
        ans = max(ans, a_route[i][1] - 1)
print(ans)

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


def x_route(x, reach):
    x_route = [-1] * n
    check = [0] * n
    stack = [x]
    check[x] = 1
    x_route[x] = 0
    while len(stack) > 0:
        tmp = stack.pop(-1)
        tmp_list = reach[tmp]
        for i in tmp_list:
            if check[i] != 1:
                stack.append(i)
                check[i] = 1
                x_route[i] = x_route[tmp] + 1
    return x_route


a_route = x_route(v, reach)
t_route = x_route(u, reach)
ans = 0
for i in range(len(a_route)):
    if t_route[i] < a_route[i]:
        ans = max(ans, a_route[i] - 1)
print(ans)

-#%% -    x_route = [[-1, -1] for _ in range(n)] +    x_route = [-1] * n -    x_route[x] = [-1, 0] +    x_route[x] = 0 -            if check[i] == 1: -                pass -            else: +            if check[i] != 1: -                x_route[i] = [tmp, x_route[tmp][1] + 1] +                x_route[i] = x_route[tmp] + 1 -    if t_route[i][1] < a_route[i][1]: -        ans = max(ans, a_route[i][1] - 1) +    if t_route[i] < a_route[i]: +        ans = max(ans, a_route[i] - 1)