R=range def J(): return map(int,input().split()) N,Q=J() P=list(J()) p=[n for n in R(N+1)] def r(i): m=p[i] while i!=m: p[i]=i=p[m] m=p[i] return i for i in R(N): if P[i]>0: A,B=r(i+1),r(P[i]) p[A]=B for q in R(Q): A,B=J() print("Yes"if r(A)==r(B)else"No")