# ABC148 F

si = lambda: eval(input())

ni = lambda: int(eval(input()))

nm = lambda: list(map(int, input().split()))

nl = lambda: list(map(int, input().split()))

N, u, v = nm()

u -= 1

v -= 1

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

for i in range(N-1):

    A, B = nm()

    A -= 1

    B -= 1

    G[A].append(B)

    G[B].append(A)



dist_u = [-1]*N

dist_v = [-1]*N

dist_u[u] = 0

dist_v[v] = 0



from collections import deque



q = deque()

q.append(u)

while q:

    x = q.popleft()

    for nx in G[x]:

        if dist_u[nx] == -1:

            q.append(nx)

            dist_u[nx] = dist_u[x]+1



q = deque()

q.append(v)

while q:

    x = q.popleft()

    for nx in G[x]:

        if dist_v[nx] == -1:

            q.append(nx)

            dist_v[nx] = dist_v[x]+1



ans = 0

for i in range(N):

    if dist_u[i] < dist_v[i] and dist_v[i] >= ans:

        ans = dist_v[i]



print((ans-1))

from collections import deque

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

G=[[] for i in range(n)]

dist_u=[-1]*n

dist_v=[-1]*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)



u-=1

v-=1



dist_u[u]=0

q=deque([u])



while q:

    cur=q.popleft()

    for nx in G[cur]:

        if dist_u[nx]==-1:

            q.append(nx)

            dist_u[nx]=dist_u[cur]+1



dist_v[v]=0

q=deque([v])



while q:

    cur=q.popleft()

    for nx in G[cur]:

        if dist_v[nx]==-1:

            q.append(nx)

            dist_v[nx]=dist_v[cur]+1

ans=0

for i in range(n):

    if dist_u[i]<dist_v[i] and dist_v[i]>=ans:

        ans=dist_v[i]

print((ans-1))





# ABC148 F
si = lambda: eval(input())
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
N, u, v = nm()
u -= 1
v -= 1
G = [[] for i in range(N)]
for i in range(N - 1):
    A, B = nm()
    A -= 1
    B -= 1
    G[A].append(B)
    G[B].append(A)
dist_u = [-1] * N
dist_v = [-1] * N
dist_u[u] = 0
dist_v[v] = 0
from collections import deque

q = deque()
q.append(u)
while q:
    x = q.popleft()
    for nx in G[x]:
        if dist_u[nx] == -1:
            q.append(nx)
            dist_u[nx] = dist_u[x] + 1
q = deque()
q.append(v)
while q:
    x = q.popleft()
    for nx in G[x]:
        if dist_v[nx] == -1:
            q.append(nx)
            dist_v[nx] = dist_v[x] + 1
ans = 0
for i in range(N):
    if dist_u[i] < dist_v[i] and dist_v[i] >= ans:
        ans = dist_v[i]
print((ans - 1))

from collections import deque

n, u, v = list(map(int, input().split()))
G = [[] for i in range(n)]
dist_u = [-1] * n
dist_v = [-1] * 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)
u -= 1
v -= 1
dist_u[u] = 0
q = deque([u])
while q:
    cur = q.popleft()
    for nx in G[cur]:
        if dist_u[nx] == -1:
            q.append(nx)
            dist_u[nx] = dist_u[cur] + 1
dist_v[v] = 0
q = deque([v])
while q:
    cur = q.popleft()
    for nx in G[cur]:
        if dist_v[nx] == -1:
            q.append(nx)
            dist_v[nx] = dist_v[cur] + 1
ans = 0
for i in range(n):
    if dist_u[i] < dist_v[i] and dist_v[i] >= ans:
        ans = dist_v[i]
print((ans - 1))

-# ABC148 F -si = lambda: eval(input()) -ni = lambda: int(eval(input())) -nm = lambda: list(map(int, input().split())) -nl = lambda: list(map(int, input().split())) -N, u, v = nm() +from collections import deque + +n, u, v = list(map(int, input().split())) +G = [[] for i in range(n)] +dist_u = [-1] * n +dist_v = [-1] * 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) -G = [[] for i in range(N)] -for i in range(N - 1): -    A, B = nm() -    A -= 1 -    B -= 1 -    G[A].append(B) -    G[B].append(A) -dist_u = [-1] * N -dist_v = [-1] * N -dist_v[v] = 0 -from collections import deque - -q = deque() -q.append(u) +q = deque([u]) -    x = q.popleft() -    for nx in G[x]: +    cur = q.popleft() +    for nx in G[cur]: -            dist_u[nx] = dist_u[x] + 1 -q = deque() -q.append(v) +            dist_u[nx] = dist_u[cur] + 1 +dist_v[v] = 0 +q = deque([v]) -    x = q.popleft() -    for nx in G[x]: +    cur = q.popleft() +    for nx in G[cur]: -            dist_v[nx] = dist_v[x] + 1 +            dist_v[nx] = dist_v[cur] + 1 -for i in range(N): +for i in range(n):