from collections import deque



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



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

for i in range(n-1):

 i,j=list(map(int,input().split()))

 tree[i-1].append(j-1)

 tree[j-1].append(i-1)



def BFS(s):

 dist=[-1 for i in range(n)]

 dist[s]=0



 que=deque()

 que.append(s)



 while que:

  x=que.popleft()

  for p in tree[x]:

   if dist[p]==-1:

    que.append(p)

    dist[p]=dist[x]+1



 return dist



u_dist=BFS(u-1)

v_dist=BFS(v-1)



l=0

for u_d,v_d in zip(u_dist,v_dist):

 if u_d<v_d:

  l=max(l,v_d)



print((l-1))
from sys import stdin

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

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

from collections import deque



n,u,v=nii()

u-=1

v-=1



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

for i in range(n-1):

  a,b=nii()

  a-=1

  b-=1

  tree[a].append(b)

  tree[b].append(a)



dist_a=[-1 for i in range(n)]

dist_a[v]=0



dist_t=[-1 for i in range(n)]

dist_t[u]=0





def BFS(dist,s):

  que=deque()

  que.append(s)



  while que:

    x=que.popleft()

    for i in tree[x]:

      if dist[i]==-1:

        que.append(i)

        dist[i]=dist[x]+1

  return dist



dist_a=BFS(dist_a,v)

dist_t=BFS(dist_t,u)



ans=0

for i in range(n):

  if dist_a[i]>dist_t[i]:

    ans=max(ans,dist_a[i]-1)



print(ans)
from collections import deque

n, u, v = list(map(int, input().split()))
tree = [[] for i in range(n)]
for i in range(n - 1):
    i, j = list(map(int, input().split()))
    tree[i - 1].append(j - 1)
    tree[j - 1].append(i - 1)


def BFS(s):
    dist = [-1 for i in range(n)]
    dist[s] = 0
    que = deque()
    que.append(s)
    while que:
        x = que.popleft()
        for p in tree[x]:
            if dist[p] == -1:
                que.append(p)
                dist[p] = dist[x] + 1
    return dist


u_dist = BFS(u - 1)
v_dist = BFS(v - 1)
l = 0
for u_d, v_d in zip(u_dist, v_dist):
    if u_d < v_d:
        l = max(l, v_d)
print((l - 1))

from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
from collections import deque

n, u, v = nii()
u -= 1
v -= 1
tree = [[] for i in range(n)]
for i in range(n - 1):
    a, b = nii()
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)
dist_a = [-1 for i in range(n)]
dist_a[v] = 0
dist_t = [-1 for i in range(n)]
dist_t[u] = 0


def BFS(dist, s):
    que = deque()
    que.append(s)
    while que:
        x = que.popleft()
        for i in tree[x]:
            if dist[i] == -1:
                que.append(i)
                dist[i] = dist[x] + 1
    return dist


dist_a = BFS(dist_a, v)
dist_t = BFS(dist_t, u)
ans = 0
for i in range(n):
    if dist_a[i] > dist_t[i]:
        ans = max(ans, dist_a[i] - 1)
print(ans)

+from sys import stdin + +nii = lambda: list(map(int, stdin.readline().split())) +lnii = lambda: list(map(int, stdin.readline().split())) -n, u, v = list(map(int, input().split())) +n, u, v = nii() +u -= 1 +v -= 1 -    i, j = list(map(int, input().split())) -    tree[i - 1].append(j - 1) -    tree[j - 1].append(i - 1) +    a, b = nii() +    a -= 1 +    b -= 1 +    tree[a].append(b) +    tree[b].append(a) +dist_a = [-1 for i in range(n)] +dist_a[v] = 0 +dist_t = [-1 for i in range(n)] +dist_t[u] = 0 -def BFS(s): -    dist = [-1 for i in range(n)] -    dist[s] = 0 +def BFS(dist, s): -        for p in tree[x]: -            if dist[p] == -1: -                que.append(p) -                dist[p] = dist[x] + 1 +        for i in tree[x]: +            if dist[i] == -1: +                que.append(i) +                dist[i] = dist[x] + 1 -u_dist = BFS(u - 1) -v_dist = BFS(v - 1) -l = 0 -for u_d, v_d in zip(u_dist, v_dist): -    if u_d < v_d: -        l = max(l, v_d) -print((l - 1)) +dist_a = BFS(dist_a, v) +dist_t = BFS(dist_t, u) +ans = 0 +for i in range(n): +    if dist_a[i] > dist_t[i]: +        ans = max(ans, dist_a[i] - 1) +print(ans)