import sys input = sys.stdin.readline N,Q=map(int,input().split()) P=list(map(int,input().split())) # UnionFind Group = [i for i in range(N+1)] # グループ分け Nodes = [1]*(N+1) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) for i in range(N): if P[i]==-1: continue Union(i+1,P[i]) for tests in range(Q): a,b=map(int,input().split()) if find(a)==find(b): print("Yes") else: print("No")