Code Festival B Union Find by shinh

d['aaa'];n;a,b,c;r(x){for(;d[x];)x=d[x];return x;}main(z){for(;~scanf("%d%d%d"+z*2,&a,&b,&c);)z?z=0,n=a:(b=r(b),c=r(c),a?puts(b-c?"NO":"YES"):b-c?d[c]=b:0);}

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

download

return to the top page