from collections import deque



N, T, A, *AB = list(map(int, open(0).read().split()))



E = [[] for _ in range(N + 1)]

for a, b in zip(*[iter(AB)] * 2):

    E[a].append(b)

    E[b].append(a)



takahashi = [-1] * (N + 1)

takahashi[T] = 0

Q = deque([T])

while Q:

    a = Q.popleft()

    for b in E[a]:

        if takahashi[b] != -1:

            continue

        takahashi[b] = takahashi[a] + 1

        Q.append(b)



aoki = [-1] * (N + 1)

aoki[A] = 0

Q = deque([A])

while Q:

    a = Q.popleft()

    for b in E[a]:

        if aoki[b] != -1:

            continue

        aoki[b] = aoki[a] + 1

        Q.append(b)



ma = 0

for t, a in zip(takahashi[1:], aoki[1:]):

    if t < a:

        ma = max(ma, a)



print((ma - 1))

from collections import deque



N, u, v, *AB = list(map(int, open(0).read().split()))



E = [[] for _ in range(N + 1)]

for a, b in zip(*[iter(AB)] * 2):

    E[a].append(b)

    E[b].append(a)



def solve(s):

    D = [-1] * (N + 1)

    D[s] = 0



    Q = deque([s])

    while Q:

        a = Q.popleft()

        for b in E[a]:

            if D[b] != -1:

                continue

            D[b] = D[a] + 1

            Q.append(b)



    return D[1:]



T = solve(u)

A = solve(v)



print((-1 + max(a for t, a in zip(T, A) if t < a)))
from collections import deque

N, T, A, *AB = list(map(int, open(0).read().split()))
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)
takahashi = [-1] * (N + 1)
takahashi[T] = 0
Q = deque([T])
while Q:
    a = Q.popleft()
    for b in E[a]:
        if takahashi[b] != -1:
            continue
        takahashi[b] = takahashi[a] + 1
        Q.append(b)
aoki = [-1] * (N + 1)
aoki[A] = 0
Q = deque([A])
while Q:
    a = Q.popleft()
    for b in E[a]:
        if aoki[b] != -1:
            continue
        aoki[b] = aoki[a] + 1
        Q.append(b)
ma = 0
for t, a in zip(takahashi[1:], aoki[1:]):
    if t < a:
        ma = max(ma, a)
print((ma - 1))

from collections import deque

N, u, v, *AB = list(map(int, open(0).read().split()))
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)


def solve(s):
    D = [-1] * (N + 1)
    D[s] = 0
    Q = deque([s])
    while Q:
        a = Q.popleft()
        for b in E[a]:
            if D[b] != -1:
                continue
            D[b] = D[a] + 1
            Q.append(b)
    return D[1:]


T = solve(u)
A = solve(v)
print((-1 + max(a for t, a in zip(T, A) if t < a)))

-N, T, A, *AB = list(map(int, open(0).read().split())) +N, u, v, *AB = list(map(int, open(0).read().split())) -takahashi = [-1] * (N + 1) -takahashi[T] = 0 -Q = deque([T]) -while Q: -    a = Q.popleft() -    for b in E[a]: -        if takahashi[b] != -1: -            continue -        takahashi[b] = takahashi[a] + 1 -        Q.append(b) -aoki = [-1] * (N + 1) -aoki[A] = 0 -Q = deque([A]) -while Q: -    a = Q.popleft() -    for b in E[a]: -        if aoki[b] != -1: -            continue -        aoki[b] = aoki[a] + 1 -        Q.append(b) -ma = 0 -for t, a in zip(takahashi[1:], aoki[1:]): -    if t < a: -        ma = max(ma, a) -print((ma - 1)) + + +def solve(s): +    D = [-1] * (N + 1) +    D[s] = 0 +    Q = deque([s]) +    while Q: +        a = Q.popleft() +        for b in E[a]: +            if D[b] != -1: +                continue +            D[b] = D[a] + 1 +            Q.append(b) +    return D[1:] + + +T = solve(u) +A = solve(v) +print((-1 + max(a for t, a in zip(T, A) if t < a)))