//yukicoder390C #include using namespace std; typedef int64_t ll; int main(){ int n,q; cin>>n>>q; map Mp;//前ー後 vector Head(0);//先頭の番号 for(int i=1;i<=n;i++){ int p; cin>>p; if(p==-1){ Head.push_back(i); }else{ Mp[p]=i; } } vector Belong(n+1,0);//先頭の番号を記録 for(int head:Head){ int h=head; Belong.at(h)=head; while(Mp.count(h)){ h=Mp[h]; Belong.at(h)=head; } } while(q--){ int a,b; cin>>a>>b; if(Belong.at(a)==Belong.at(b)){ cout<<"Yes"<