#f
N,U,V = map(int,input().split())
U-=1
V-=1
tree =[[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a-=1
    b-=1
    tree[a].append(b)
    tree[b].append(a)

from collections import deque
def shortest(tree,start):
    from_start=[0]*N
    q = deque([(-1,start,0)])
    while q:
        parent,x,time = q.popleft()
        for y in tree[x]:
            if y == parent:
                continue
            q.append((x,y,time+1))
        from_start[x]=time
    return from_start

from_u = shortest(tree,U)
from_v = shortest(tree,V)

print(max(uu for uu,vv in zip(from_u,from_v) if uu<vv ) )