N, Q = map(int, input().split()) P = tuple(map(int, input().split())) s = set(range(1, N+1)) for p in P: if p in s: s.remove(p) g = [-1] * N for i in s: p = i - 1 lis = [p] while P[p] != -1: p = P[p] - 1 lis.append(p) for j in lis: g[j] = p for _ in range(Q): A, B = map(lambda x: int(x) - 1, input().split()) if g[A] == g[B]: print('Yes') else: print('No')