N, u, v = map(int,input().split())
edges=[list(map(int,input().split())) for i in range(N)]
root = [[] for i in range(N-1)]
ans = 100000000
for a,b in edges:
    root[a-1]+=b-1
    root[b-1]+=a-1
def chase_move(my_pos,opponent_pos):
    if opponent_pos in root[my_pos]:
        tmp = [opponent_pos]
        return tmp
    else:
        tmp = root[my_pos][:]
        return tmp

def escape_move(my_pos,opponent_pos):
    if opponent_pos in root[my_pos]:
        tmp = root[my_pos][:]
        tmp.remove(opponent_pos)
        return tmp
    else:
        tmp = root[my_pos][:]
        return tmp
        
def main(takahashi_pos,aoki_pos,cnt,turn):
    global ans
    if takahashi_pos==aoki_pos:
        if cnt<ans:
            ans=cnt
    if ans<=cnt:
        return
    if turn == 0:
        tmp = escape_move(takahashi_pos,aoki_pos)
        for i in tmp:
            main(i,aoki_pos,cnt,1)
    elif turn == 1:
        cnt+=1
        tmp = chase_move(aoki_pos,takahashi_pos)
        for i in tmp:
            main(takahashi_pos,i,cnt,0)
main(u,v,0,0)
print(ans)