Code Festival B Union Find by mitchs

#!ruby -na
q,a,b=$F.map &f=->x{$:[x=x.to_i+8]=x==(t=$:[x]||x)?x:f[t-8]}
/^1 /?puts(a==b ?:YES:'NO'):$:[a]=b

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

download

return to the top page