Code Festival B Union Find by mitchs

#!ruby -na
q,a,b=$F.map &f=proc{|x|$*[x=x.to_i]=x==(t=$*[x]||x)?x:f[t]}
/^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