n,q=map(int,input().split()) p=list(map(int,input().split())) r=list(range(n)) c=[int(p[i]==-1) for i in range(n)] def root(x): p=x l=[p] while r[p]!=p: p=r[p] l.append(p) for p in l: r[p]=l[-1] return r[x] def union(x,y): rx=root(x) ry=root(y) if rx==ry: return if (c[rx],rx)<(c[ry],ry): rx,ry=ry,rx r[ry]=rx return for i in range(n): if p[i]!=-1: p[i]-=1 union(i,p[i]) for i in range(q): a,b=map(int,input().split()) a-=1 b-=1 print(["No","Yes"][root(a)==root(b)])