Code Festival B Union Find by ciel

#import<cstdio>
int p[1<<17],x,y;main(){for(x=1e5;p[x]=--x;);for(scanf("%d%d",p,p);~scanf("%d%d%d",p,&x,&y);!*p?p[x]=y:puts(x-y?"NO":"YES"))for(;x-p[x]+y-p[y];y=p[y])x=p[x];}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page