c;A[7<<14];main(b){for(;A[c=A[c]?:c]+A[b=A[b]?:b]||~scanf("%d%d%d",A,gets(&b),&c,*A?puts(b-c?"NO":"YES"):b-c?A[b]=c:0););}