Code Festival B Union Find by chocobi

g[100001],a,b,c;main(s){for(gets(g);++a<100001;)g[a]=a;for(;~scanf("%d%d%d",&a,&b,&c);)if(a){for(s=b;a=g[b],a-c&&a-s;)b=a;puts(a-c?"NO":"YES");}else a=g[b],g[b]=g[c],g[c]=a;}

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

download

return to the top page