N, Q = map(int, input().split()) P = list(map(int, input().split())) train_line = [0] * N line_num = 1 for i in range(N): if P[i] == -1: train_line[i] = line_num line_num += 1 for i in range(N): if P[i] != -1: train_line[i] = train_line[P[i]-1] for _ in range(Q): A, B = map(int, input().split()) if train_line[A-1] == train_line[B-1]: print("Yes") else: print("No")