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

inf = 10 ** 6

u -= 1

v -= 1

peer = [[] for _ in range(n)]

for _ in range(n-1):

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

  a -= 1

  b -= 1

  peer[a].append(b)

  peer[b].append(a)

seen = [0 for _ in range(n)]

rank = [0 for _ in range(n)]

seen[v] = 1

now = [v]

pst = [[] for _ in range(n)]

pre = [inf for _ in range(n)]

while now:

  last = now

  now = []

  for x in last:

    for y in peer[x]:

      if seen[y] == 0:

        seen[y] = 1

        rank[y] = rank[x] + 1

        pst[x].append(y)

        pre[y] = x

        now.append(y)

#print(rank)

r = rank[u]

if r % 2 == 0:

  m = r//2 + 1

  M = u

  for _ in range(r-m):

    M = pre[M]

  now = [M]

  while now != []:

    last = now

    now = []

    for x in last:

      for y in pst[x]:

        now.append(y)

  ans = rank[last[0]] - m + r - m + 1

  #print(r,m,M,rank[last[0]],last[0])

  #print(0,ans)

else:

  m = r//2 + 1

  M = u

  for _ in range(r-m):

    M = pre[M]

  now = [M]

  while now != []:

    last = now

    now = []

    for x in last:

      for y in pst[x]:

        now.append(y)

  ans = rank[last[0]] - m + r - m

  #print(r,m,M,rank[last[0]],last[0])

  #print(1,ans)

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

u -= 1

v -= 1

peer = [[] for _ in range(n)]

for _ in range(n-1):

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

  a -= 1

  b -= 1

  peer[a].append(b)

  peer[b].append(a)

rank = [10**6 for _ in range(n)]

seen = [0 for _ in range(n)]

pre = [10**6 for _ in range(n)]

pst = [[] for _ in range(n)]

seen[v] = 1

rank[v] = 0

now = [v]

while now:

  last = now

  now = []

  for x in last:

    for y in peer[x]:

      if seen[y] == 0:

        seen[y] += 1

        rank[y] = rank[x] + 1

        now.append(y)

        pre[y] = x

        pst[x].append(y)

#print(rank)

back = (rank[u]-1) // 2

tar = u

for _ in range(back):

  tar = pre[tar]

depth = -1

now = [tar]

while now:

  depth += 1

  last = now

  now = []

  for x in last:

    now += pst[x]

#print(tar,depth,last)

if rank[u] % 2 == 1:

  print((back + depth))

else:

  print((back + depth + 1))
n, u, v = list(map(int, input().split()))
inf = 10**6
u -= 1
v -= 1
peer = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    peer[a].append(b)
    peer[b].append(a)
seen = [0 for _ in range(n)]
rank = [0 for _ in range(n)]
seen[v] = 1
now = [v]
pst = [[] for _ in range(n)]
pre = [inf for _ in range(n)]
while now:
    last = now
    now = []
    for x in last:
        for y in peer[x]:
            if seen[y] == 0:
                seen[y] = 1
                rank[y] = rank[x] + 1
                pst[x].append(y)
                pre[y] = x
                now.append(y)
# print(rank)
r = rank[u]
if r % 2 == 0:
    m = r // 2 + 1
    M = u
    for _ in range(r - m):
        M = pre[M]
    now = [M]
    while now != []:
        last = now
        now = []
        for x in last:
            for y in pst[x]:
                now.append(y)
    ans = rank[last[0]] - m + r - m + 1
    # print(r,m,M,rank[last[0]],last[0])
    # print(0,ans)
else:
    m = r // 2 + 1
    M = u
    for _ in range(r - m):
        M = pre[M]
    now = [M]
    while now != []:
        last = now
        now = []
        for x in last:
            for y in pst[x]:
                now.append(y)
    ans = rank[last[0]] - m + r - m
    # print(r,m,M,rank[last[0]],last[0])
    # print(1,ans)
print(ans)

n, u, v = list(map(int, input().split()))
u -= 1
v -= 1
peer = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    peer[a].append(b)
    peer[b].append(a)
rank = [10**6 for _ in range(n)]
seen = [0 for _ in range(n)]
pre = [10**6 for _ in range(n)]
pst = [[] for _ in range(n)]
seen[v] = 1
rank[v] = 0
now = [v]
while now:
    last = now
    now = []
    for x in last:
        for y in peer[x]:
            if seen[y] == 0:
                seen[y] += 1
                rank[y] = rank[x] + 1
                now.append(y)
                pre[y] = x
                pst[x].append(y)
# print(rank)
back = (rank[u] - 1) // 2
tar = u
for _ in range(back):
    tar = pre[tar]
depth = -1
now = [tar]
while now:
    depth += 1
    last = now
    now = []
    for x in last:
        now += pst[x]
# print(tar,depth,last)
if rank[u] % 2 == 1:
    print((back + depth))
else:
    print((back + depth + 1))

-inf = 10**6 +rank = [10**6 for _ in range(n)] -rank = [0 for _ in range(n)] +pre = [10**6 for _ in range(n)] +pst = [[] for _ in range(n)] +rank[v] = 0 -pst = [[] for _ in range(n)] -pre = [inf for _ in range(n)] -                seen[y] = 1 +                seen[y] += 1 +                now.append(y) +                pre[y] = x -                pre[y] = x -                now.append(y) -r = rank[u] -if r % 2 == 0: -    m = r // 2 + 1 -    M = u -    for _ in range(r - m): -        M = pre[M] -    now = [M] -    while now != []: -        last = now -        now = [] -        for x in last: -            for y in pst[x]: -                now.append(y) -    ans = rank[last[0]] - m + r - m + 1 -    # print(r,m,M,rank[last[0]],last[0]) -    # print(0,ans) +back = (rank[u] - 1) // 2 +tar = u +for _ in range(back): +    tar = pre[tar] +depth = -1 +now = [tar] +while now: +    depth += 1 +    last = now +    now = [] +    for x in last: +        now += pst[x] +# print(tar,depth,last) +if rank[u] % 2 == 1: +    print((back + depth)) -    m = r // 2 + 1 -    M = u -    for _ in range(r - m): -        M = pre[M] -    now = [M] -    while now != []: -        last = now -        now = [] -        for x in last: -            for y in pst[x]: -                now.append(y) -    ans = rank[last[0]] - m + r - m -    # print(r,m,M,rank[last[0]],last[0]) -    # print(1,ans) -print(ans) +    print((back + depth + 1))