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

u-=1

v-=1

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

for _ in range(n-1):

  a,b=[int(x)-1 for x in input().split()]

  ki[a].append(b)

  ki[b].append(a)

du=[0]*n

dv=[0]*n

from collections import deque

def distance(i):

  seen=[-1]*n

  seen[i]=0

  todo=deque([i])

  while todo:

    t=todo.popleft()

    l=ki[t]

    d=seen[t]

    for li in l:

      if seen[li]==-1:

        seen[li]=d+1

        todo.append(li)

  return seen

du=distance(u)

dv=distance(v)

ans=0

for i in range(n):

  if dv[i]>du[i]:

    ans=max(ans,dv[i])

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

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

for _ in range(n-1):

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

  a,b=a-1,b-1

  ki[a].append(b)

  ki[b].append(a)

# 次数

dn=[len(ki[i]) for i in range(n)]

inf=float('inf')

dt=[inf]*n

da=[inf]*n

u,v=u-1,v-1

from collections import deque

todo=deque([u])

dt[u]=0

while todo:

  x=todo.popleft()

  for nx in ki[x]:

    if dt[nx]>dt[x]+1:

      dt[nx]=dt[x]+1

      todo.append(nx)

todo=deque([v])

da[v]=0

while todo:

  x=todo.popleft()

  for nx in ki[x]:

    if da[nx]>da[x]+1:

      da[nx]=da[x]+1

      todo.append(nx)

ans=0

for i in range(n):

  if dn[i]>1 and dt[i]<=da[i]:ans=max(ans,da[i])

print(ans)

exit()

print(dn)

print(dt)

print(da)
n, u, v = list(map(int, input().split()))
u -= 1
v -= 1
ki = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(x) - 1 for x in input().split()]
    ki[a].append(b)
    ki[b].append(a)
du = [0] * n
dv = [0] * n
from collections import deque


def distance(i):
    seen = [-1] * n
    seen[i] = 0
    todo = deque([i])
    while todo:
        t = todo.popleft()
        l = ki[t]
        d = seen[t]
        for li in l:
            if seen[li] == -1:
                seen[li] = d + 1
                todo.append(li)
    return seen


du = distance(u)
dv = distance(v)
ans = 0
for i in range(n):
    if dv[i] > du[i]:
        ans = max(ans, dv[i])
print((ans - 1))

n, u, v = list(map(int, input().split()))
ki = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    ki[a].append(b)
    ki[b].append(a)
# 次数
dn = [len(ki[i]) for i in range(n)]
inf = float("inf")
dt = [inf] * n
da = [inf] * n
u, v = u - 1, v - 1
from collections import deque

todo = deque([u])
dt[u] = 0
while todo:
    x = todo.popleft()
    for nx in ki[x]:
        if dt[nx] > dt[x] + 1:
            dt[nx] = dt[x] + 1
            todo.append(nx)
todo = deque([v])
da[v] = 0
while todo:
    x = todo.popleft()
    for nx in ki[x]:
        if da[nx] > da[x] + 1:
            da[nx] = da[x] + 1
            todo.append(nx)
ans = 0
for i in range(n):
    if dn[i] > 1 and dt[i] <= da[i]:
        ans = max(ans, da[i])
print(ans)
exit()
print(dn)
print(dt)
print(da)

-u -= 1 -v -= 1 -    a, b = [int(x) - 1 for x in input().split()] +    a, b = list(map(int, input().split())) +    a, b = a - 1, b - 1 -du = [0] * n -dv = [0] * n +# 次数 +dn = [len(ki[i]) for i in range(n)] +inf = float("inf") +dt = [inf] * n +da = [inf] * n +u, v = u - 1, v - 1 - -def distance(i): -    seen = [-1] * n -    seen[i] = 0 -    todo = deque([i]) -    while todo: -        t = todo.popleft() -        l = ki[t] -        d = seen[t] -        for li in l: -            if seen[li] == -1: -                seen[li] = d + 1 -                todo.append(li) -    return seen - - -du = distance(u) -dv = distance(v) +todo = deque([u]) +dt[u] = 0 +while todo: +    x = todo.popleft() +    for nx in ki[x]: +        if dt[nx] > dt[x] + 1: +            dt[nx] = dt[x] + 1 +            todo.append(nx) +todo = deque([v]) +da[v] = 0 +while todo: +    x = todo.popleft() +    for nx in ki[x]: +        if da[nx] > da[x] + 1: +            da[nx] = da[x] + 1 +            todo.append(nx) -    if dv[i] > du[i]: -        ans = max(ans, dv[i]) -print((ans - 1)) +    if dn[i] > 1 and dt[i] <= da[i]: +        ans = max(ans, da[i]) +print(ans) +exit() +print(dn) +print(dt) +print(da)