import sys

sys.setrecursionlimit(10**9)

f=lambda:list(map(int,sys.stdin.readline().split()))

n,st,sa=f()

g=[set() for _ in range(n)]

for _ in range(n-1):

  a,b=f()

  g[a-1].add(b-1)

  g[b-1].add(a-1)

def dfs(l,v,p=-1,d=0):

  l[v]=d

  for c in g[v]:

    if c!=p: dfs(l,c,v,d+1)

lt=[0]*n

dfs(lt,st-1)

la=[0]*n

dfs(la,sa-1)

print((max(la[i] for i in range(n) if lt[i]<la[i])-1))
f=lambda:list(map(int,input().split()))

n,st,sa=f()

g=[set() for _ in range(n)]

for _ in range(n-1):

  a,b=f()

  g[a-1].add(b-1)

  g[b-1].add(a-1)

def bfs(s):

  l=[-1]*n; l[s]=0; q=[s]

  while q:

    v=q.pop(); d=l[v]+1

    for c in g[v]:

      if l[c]<0: l[c]=d; q+=[c]

  return l

lt=bfs(st-1)

la=bfs(sa-1)

print((max(la[i] for i in range(n) if lt[i]<la[i])-1))
import sys

sys.setrecursionlimit(10**9)
f = lambda: list(map(int, sys.stdin.readline().split()))
n, st, sa = f()
g = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = f()
    g[a - 1].add(b - 1)
    g[b - 1].add(a - 1)


def dfs(l, v, p=-1, d=0):
    l[v] = d
    for c in g[v]:
        if c != p:
            dfs(l, c, v, d + 1)


lt = [0] * n
dfs(lt, st - 1)
la = [0] * n
dfs(la, sa - 1)
print((max(la[i] for i in range(n) if lt[i] < la[i]) - 1))

f = lambda: list(map(int, input().split()))
n, st, sa = f()
g = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = f()
    g[a - 1].add(b - 1)
    g[b - 1].add(a - 1)


def bfs(s):
    l = [-1] * n
    l[s] = 0
    q = [s]
    while q:
        v = q.pop()
        d = l[v] + 1
        for c in g[v]:
            if l[c] < 0:
                l[c] = d
                q += [c]
    return l


lt = bfs(st - 1)
la = bfs(sa - 1)
print((max(la[i] for i in range(n) if lt[i] < la[i]) - 1))

-import sys - -sys.setrecursionlimit(10**9) -f = lambda: list(map(int, sys.stdin.readline().split())) +f = lambda: list(map(int, input().split())) -def dfs(l, v, p=-1, d=0): -    l[v] = d -    for c in g[v]: -        if c != p: -            dfs(l, c, v, d + 1) +def bfs(s): +    l = [-1] * n +    l[s] = 0 +    q = [s] +    while q: +        v = q.pop() +        d = l[v] + 1 +        for c in g[v]: +            if l[c] < 0: +                l[c] = d +                q += [c] +    return l -lt = [0] * n -dfs(lt, st - 1) -la = [0] * n -dfs(la, sa - 1) +lt = bfs(st - 1) +la = bfs(sa - 1)