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

AB = [list(map(int, input().split())) for _ in range(N - 1)]



graph = [[] for _ in range(N)]

for Ai, Bi in AB:

    graph[Ai - 1].append(Bi - 1)

    graph[Bi - 1].append(Ai - 1)



import heapq



# tak table

d_tak = [10 ** 9 + 7] * N

p_tak = [None] * N

d_tak[u - 1] = 0

q = [(u - 1, 0)]

while len(q) > 0:

    src, pen = heapq.heappop(q)

    for dst in graph[src]:

        if d_tak[dst] > pen + 1:

            d_tak[dst] = pen + 1

            p_tak[dst] = src

            heapq.heappush(q, (dst, pen + 1))



# aok table

d_aok = [10 ** 9 + 7] * N

p_aok = [None] * N

d_aok[v - 1] = 0

q = [(v - 1, 0)]

while len(q) > 0:

    src, pen = heapq.heappop(q)

    for dst in graph[src]:

        if d_aok[dst] > pen + 1:

            d_aok[dst] = pen + 1

            p_aok[dst] = src

            heapq.heappush(q, (dst, pen + 1))



# where for tak to escape

i_ans = None

ans_tmp = 0

for i in range(N):

    if d_tak[i] < d_aok[i] and ans_tmp < d_aok[i]:

        ans_tmp = d_aok[i]

        i_ans = i



# where is aok when tak stops

pos_aok = i_ans

for j in range(d_aok[i_ans] - d_tak[i_ans]):

    pos_aok = p_aok[pos_aok]



# aok table 2

d_aok2 = [10 ** 9 + 7] * N

p_aok2 = [None] * N

d_aok2[v - 1] = 0

q = [(v - 1, 0)]

while len(q) > 0:

    src, pen = heapq.heappop(q)

    for dst in graph[src]:

        if d_aok2[dst] > pen + 1:

            d_aok2[dst] = pen + 1

            p_aok2[dst] = src

            heapq.heappush(q, (dst, pen + 1))



print((max(0, d_aok2[i_ans] - 1)))
N, u, v = list(map(int, input().split()))

AB = [list(map(int, input().split())) for _ in range(N - 1)]



graph = [[] for _ in range(N)]

for i, (Ai, Bi) in enumerate(AB):

    graph[Ai - 1].append(Bi - 1)

    graph[Bi - 1].append(Ai - 1)



import heapq

MY_INF = 10 ** 18



q = [(0, u - 1)]

d_u = [MY_INF] * N

d_u[u - 1] = 0

while len(q) > 0:

    dist, src = heapq.heappop(q)

    for dst in graph[src]:

        dist_tmp = dist + 1

        if d_u[dst] > dist_tmp:

            d_u[dst] = dist_tmp

            heapq.heappush(q, (dist_tmp, dst))



q = [(0, v - 1)]

d_v = [MY_INF] * N

d_v[v - 1] = 0

while len(q) > 0:

    dist, src = heapq.heappop(q)

    for dst in graph[src]:

        dist_tmp = dist + 1

        if d_v[dst] > dist_tmp:

            d_v[dst] = dist_tmp

            heapq.heappush(q, (dist_tmp, dst))



# print("#", d_u)

# print("#", d_v)

            

ans = 0

for i in range(N):

    if d_u[i] < d_v[i] and ans < d_v[i] - 1:

        ans = d_v[i] - 1



print(ans)
N, u, v = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N)]
for Ai, Bi in AB:
    graph[Ai - 1].append(Bi - 1)
    graph[Bi - 1].append(Ai - 1)
import heapq

# tak table
d_tak = [10**9 + 7] * N
p_tak = [None] * N
d_tak[u - 1] = 0
q = [(u - 1, 0)]
while len(q) > 0:
    src, pen = heapq.heappop(q)
    for dst in graph[src]:
        if d_tak[dst] > pen + 1:
            d_tak[dst] = pen + 1
            p_tak[dst] = src
            heapq.heappush(q, (dst, pen + 1))
# aok table
d_aok = [10**9 + 7] * N
p_aok = [None] * N
d_aok[v - 1] = 0
q = [(v - 1, 0)]
while len(q) > 0:
    src, pen = heapq.heappop(q)
    for dst in graph[src]:
        if d_aok[dst] > pen + 1:
            d_aok[dst] = pen + 1
            p_aok[dst] = src
            heapq.heappush(q, (dst, pen + 1))
# where for tak to escape
i_ans = None
ans_tmp = 0
for i in range(N):
    if d_tak[i] < d_aok[i] and ans_tmp < d_aok[i]:
        ans_tmp = d_aok[i]
        i_ans = i
# where is aok when tak stops
pos_aok = i_ans
for j in range(d_aok[i_ans] - d_tak[i_ans]):
    pos_aok = p_aok[pos_aok]
# aok table 2
d_aok2 = [10**9 + 7] * N
p_aok2 = [None] * N
d_aok2[v - 1] = 0
q = [(v - 1, 0)]
while len(q) > 0:
    src, pen = heapq.heappop(q)
    for dst in graph[src]:
        if d_aok2[dst] > pen + 1:
            d_aok2[dst] = pen + 1
            p_aok2[dst] = src
            heapq.heappush(q, (dst, pen + 1))
print((max(0, d_aok2[i_ans] - 1)))

N, u, v = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N)]
for i, (Ai, Bi) in enumerate(AB):
    graph[Ai - 1].append(Bi - 1)
    graph[Bi - 1].append(Ai - 1)
import heapq

MY_INF = 10**18
q = [(0, u - 1)]
d_u = [MY_INF] * N
d_u[u - 1] = 0
while len(q) > 0:
    dist, src = heapq.heappop(q)
    for dst in graph[src]:
        dist_tmp = dist + 1
        if d_u[dst] > dist_tmp:
            d_u[dst] = dist_tmp
            heapq.heappush(q, (dist_tmp, dst))
q = [(0, v - 1)]
d_v = [MY_INF] * N
d_v[v - 1] = 0
while len(q) > 0:
    dist, src = heapq.heappop(q)
    for dst in graph[src]:
        dist_tmp = dist + 1
        if d_v[dst] > dist_tmp:
            d_v[dst] = dist_tmp
            heapq.heappush(q, (dist_tmp, dst))
# print("#", d_u)
# print("#", d_v)
ans = 0
for i in range(N):
    if d_u[i] < d_v[i] and ans < d_v[i] - 1:
        ans = d_v[i] - 1
print(ans)

-for Ai, Bi in AB: +for i, (Ai, Bi) in enumerate(AB): -# tak table -d_tak = [10**9 + 7] * N -p_tak = [None] * N -d_tak[u - 1] = 0 -q = [(u - 1, 0)] +MY_INF = 10**18 +q = [(0, u - 1)] +d_u = [MY_INF] * N +d_u[u - 1] = 0 -    src, pen = heapq.heappop(q) +    dist, src = heapq.heappop(q) -        if d_tak[dst] > pen + 1: -            d_tak[dst] = pen + 1 -            p_tak[dst] = src -            heapq.heappush(q, (dst, pen + 1)) -# aok table -d_aok = [10**9 + 7] * N -p_aok = [None] * N -d_aok[v - 1] = 0 -q = [(v - 1, 0)] +        dist_tmp = dist + 1 +        if d_u[dst] > dist_tmp: +            d_u[dst] = dist_tmp +            heapq.heappush(q, (dist_tmp, dst)) +q = [(0, v - 1)] +d_v = [MY_INF] * N +d_v[v - 1] = 0 -    src, pen = heapq.heappop(q) +    dist, src = heapq.heappop(q) -        if d_aok[dst] > pen + 1: -            d_aok[dst] = pen + 1 -            p_aok[dst] = src -            heapq.heappush(q, (dst, pen + 1)) -# where for tak to escape -i_ans = None -ans_tmp = 0 +        dist_tmp = dist + 1 +        if d_v[dst] > dist_tmp: +            d_v[dst] = dist_tmp +            heapq.heappush(q, (dist_tmp, dst)) +# print("#", d_u) +# print("#", d_v) +ans = 0 -    if d_tak[i] < d_aok[i] and ans_tmp < d_aok[i]: -        ans_tmp = d_aok[i] -        i_ans = i -# where is aok when tak stops -pos_aok = i_ans -for j in range(d_aok[i_ans] - d_tak[i_ans]): -    pos_aok = p_aok[pos_aok] -# aok table 2 -d_aok2 = [10**9 + 7] * N -p_aok2 = [None] * N -d_aok2[v - 1] = 0 -q = [(v - 1, 0)] -while len(q) > 0: -    src, pen = heapq.heappop(q) -    for dst in graph[src]: -        if d_aok2[dst] > pen + 1: -            d_aok2[dst] = pen + 1 -            p_aok2[dst] = src -            heapq.heappush(q, (dst, pen + 1)) -print((max(0, d_aok2[i_ans] - 1))) +    if d_u[i] < d_v[i] and ans < d_v[i] - 1: +        ans = d_v[i] - 1 +print(ans)