Code Festival B Union Find by ciel

P=[*0..1e5];r=->(a){P[a]=a==P[a]?a:r[P[a]]};gets;while gets;t,x,y=$_.split.map &:to_i;x=r[x];y=r[y];t>0?puts(x==y ?:YES: :NO):P[x]=y;end

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

download

return to the top page