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

import sys

sys.setrecursionlimit(10**6)

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

for i in range(N-1):

    a,b=list(map(int, input().split()))

    T[a-1].append(b-1)

    T[b-1].append(a-1)





def dfs(start):

    tolist=T[start]

    nowd=done[start]

    for next_n in tolist:

        if done[next_n]==-1:

            done[next_n]=nowd+1

            dfs(next_n)



done=[-1]*N

done[u-1]=0

dfs(u-1)

dtaka=done.copy()

done=[-1]*N

done[v-1]=0

dfs(v-1)

dao=done.copy()

ans=0

for i in range(N):

    t=dtaka[i]

    a=dao[i]

    if a>t:

        ans=max(ans, a)

print((ans-1))

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

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



for i in range(N-1):

    a,b=list(map(int, input().split()))

    G[a-1].append(b-1)

    G[b-1].append(a-1)







from collections import deque



q=deque([])

q.append((v-1,0))

done1=[-1]*N



while q:

    now, dist = q.popleft()

    done1[now]=dist

    for i in G[now]:

        if done1[i]!=-1:

            continue

        q.append((i,dist+1))



q=deque([])

q.append((u-1,0))

done2=[-1]*N



while q:

    now, dist = q.popleft()

    done2[now]=dist

    for i in G[now]:

        if done2[i]!=-1:

            continue

        q.append((i,dist+1))



goal=0

for i in range(N):

    if done1[i]>done2[i]:

        goal=max(goal, done1[i])



ans=goal-1

#print(goal, done1[u-1], done2[v-1])

#print(done1, done2)

print(ans)
N, u, v = list(map(int, input().split()))
import sys

sys.setrecursionlimit(10**6)
T = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    T[a - 1].append(b - 1)
    T[b - 1].append(a - 1)


def dfs(start):
    tolist = T[start]
    nowd = done[start]
    for next_n in tolist:
        if done[next_n] == -1:
            done[next_n] = nowd + 1
            dfs(next_n)


done = [-1] * N
done[u - 1] = 0
dfs(u - 1)
dtaka = done.copy()
done = [-1] * N
done[v - 1] = 0
dfs(v - 1)
dao = done.copy()
ans = 0
for i in range(N):
    t = dtaka[i]
    a = dao[i]
    if a > t:
        ans = max(ans, a)
print((ans - 1))

N, u, v = list(map(int, input().split()))
G = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
from collections import deque

q = deque([])
q.append((v - 1, 0))
done1 = [-1] * N
while q:
    now, dist = q.popleft()
    done1[now] = dist
    for i in G[now]:
        if done1[i] != -1:
            continue
        q.append((i, dist + 1))
q = deque([])
q.append((u - 1, 0))
done2 = [-1] * N
while q:
    now, dist = q.popleft()
    done2[now] = dist
    for i in G[now]:
        if done2[i] != -1:
            continue
        q.append((i, dist + 1))
goal = 0
for i in range(N):
    if done1[i] > done2[i]:
        goal = max(goal, done1[i])
ans = goal - 1
# print(goal, done1[u-1], done2[v-1])
# print(done1, done2)
print(ans)

-import sys - -sys.setrecursionlimit(10**6) -T = [[] for _ in range(N)] +G = [[] for _ in range(N)] -    T[a - 1].append(b - 1) -    T[b - 1].append(a - 1) +    G[a - 1].append(b - 1) +    G[b - 1].append(a - 1) +from collections import deque - -def dfs(start): -    tolist = T[start] -    nowd = done[start] -    for next_n in tolist: -        if done[next_n] == -1: -            done[next_n] = nowd + 1 -            dfs(next_n) - - -done = [-1] * N -done[u - 1] = 0 -dfs(u - 1) -dtaka = done.copy() -done = [-1] * N -done[v - 1] = 0 -dfs(v - 1) -dao = done.copy() -ans = 0 +q = deque([]) +q.append((v - 1, 0)) +done1 = [-1] * N +while q: +    now, dist = q.popleft() +    done1[now] = dist +    for i in G[now]: +        if done1[i] != -1: +            continue +        q.append((i, dist + 1)) +q = deque([]) +q.append((u - 1, 0)) +done2 = [-1] * N +while q: +    now, dist = q.popleft() +    done2[now] = dist +    for i in G[now]: +        if done2[i] != -1: +            continue +        q.append((i, dist + 1)) +goal = 0 -    t = dtaka[i] -    a = dao[i] -    if a > t: -        ans = max(ans, a) -print((ans - 1)) +    if done1[i] > done2[i]: +        goal = max(goal, done1[i]) +ans = goal - 1 +# print(goal, done1[u-1], done2[v-1]) +# print(done1, done2) +print(ans)