from collections import deque





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

u -= 1

v -= 1

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

for _ in range(N - 1):

    A, B = list(map(int, input().split()))

    edge[A - 1].append(B - 1)

    edge[B - 1].append(A - 1)



INF = 10 ** 6

lenA = [INF] * N

q = deque()

q.append((v, 0))

lenA[v] = 0

while len(q) > 0:

    p, step = q.popleft()

    for np in edge[p]:

        if lenA[np] == INF:

            lenA[np] = step + 1

            q.append((np, step + 1))





lenT = [INF] * N

q = deque()

q.append((u, 0))

lenT[u] = 0

ans = 0

while len(q) > 0:

    p, step = q.popleft()

    if len(edge[p]) == 1:

        ans = max(ans, step + (lenA[p] - step) - 1)

    for np in edge[p]:

        if lenT[np] == INF and lenA[np] > step + 1:

            lenT[np] = step + 1

            q.append((np, step + 1))



print(ans)

from collections import deque

import sys



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

u -= 1; v -= 1

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

for s in sys.stdin.readlines():

    A, B = [int(x) - 1 for x in s.split()]

    edge[A].append(B)

    edge[B].append(A)



INF = float('inf')



# Aoki

pathV = [INF] * N

pathV[v] = 0

q = deque()

q.append((v, 0))

while q:

    p, d = q.popleft()

    nd = d + 1

    for np in edge[p]:

        if pathV[np] > nd:

            pathV[np] = nd

            q.append((np, nd))



# Takahashi

ans = 0

pathU = [INF] * N

pathU[u] = 0

q = deque()

q.append((u, 0))

while q:

    p, d = q.popleft()

    nd = d + 1

    if len(edge[p]) == 1:

        ans = max(ans, pathV[p] - 1)

    for np in edge[p]:

        if pathU[np] > nd and pathV[np] > nd:

            pathU[np] = nd

            q.append((np, nd))



print(ans)

from collections import deque

N, u, v = list(map(int, input().split()))
u -= 1
v -= 1
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    A, B = list(map(int, input().split()))
    edge[A - 1].append(B - 1)
    edge[B - 1].append(A - 1)
INF = 10**6
lenA = [INF] * N
q = deque()
q.append((v, 0))
lenA[v] = 0
while len(q) > 0:
    p, step = q.popleft()
    for np in edge[p]:
        if lenA[np] == INF:
            lenA[np] = step + 1
            q.append((np, step + 1))
lenT = [INF] * N
q = deque()
q.append((u, 0))
lenT[u] = 0
ans = 0
while len(q) > 0:
    p, step = q.popleft()
    if len(edge[p]) == 1:
        ans = max(ans, step + (lenA[p] - step) - 1)
    for np in edge[p]:
        if lenT[np] == INF and lenA[np] > step + 1:
            lenT[np] = step + 1
            q.append((np, step + 1))
print(ans)

from collections import deque
import sys

N, u, v = list(map(int, input().split()))
u -= 1
v -= 1
edge = [[] for _ in range(N)]
for s in sys.stdin.readlines():
    A, B = [int(x) - 1 for x in s.split()]
    edge[A].append(B)
    edge[B].append(A)
INF = float("inf")
# Aoki
pathV = [INF] * N
pathV[v] = 0
q = deque()
q.append((v, 0))
while q:
    p, d = q.popleft()
    nd = d + 1
    for np in edge[p]:
        if pathV[np] > nd:
            pathV[np] = nd
            q.append((np, nd))
# Takahashi
ans = 0
pathU = [INF] * N
pathU[u] = 0
q = deque()
q.append((u, 0))
while q:
    p, d = q.popleft()
    nd = d + 1
    if len(edge[p]) == 1:
        ans = max(ans, pathV[p] - 1)
    for np in edge[p]:
        if pathU[np] > nd and pathV[np] > nd:
            pathU[np] = nd
            q.append((np, nd))
print(ans)

+import sys -for _ in range(N - 1): -    A, B = list(map(int, input().split())) -    edge[A - 1].append(B - 1) -    edge[B - 1].append(A - 1) -INF = 10**6 -lenA = [INF] * N +for s in sys.stdin.readlines(): +    A, B = [int(x) - 1 for x in s.split()] +    edge[A].append(B) +    edge[B].append(A) +INF = float("inf") +# Aoki +pathV = [INF] * N +pathV[v] = 0 -lenA[v] = 0 -while len(q) > 0: -    p, step = q.popleft() +while q: +    p, d = q.popleft() +    nd = d + 1 -        if lenA[np] == INF: -            lenA[np] = step + 1 -            q.append((np, step + 1)) -lenT = [INF] * N +        if pathV[np] > nd: +            pathV[np] = nd +            q.append((np, nd)) +# Takahashi +ans = 0 +pathU = [INF] * N +pathU[u] = 0 -lenT[u] = 0 -ans = 0 -while len(q) > 0: -    p, step = q.popleft() +while q: +    p, d = q.popleft() +    nd = d + 1 -        ans = max(ans, step + (lenA[p] - step) - 1) +        ans = max(ans, pathV[p] - 1) -        if lenT[np] == INF and lenA[np] > step + 1: -            lenT[np] = step + 1 -            q.append((np, step + 1)) +        if pathU[np] > nd and pathV[np] > nd: +            pathU[np] = nd +            q.append((np, nd))