Code Festival B Union Find by mitchs

r=raw_input
r()
p={}
def f(x):
 if x!=p.get(x,x):p[x]=x=f(p[x])
 return x
while 1:
 q,a,b=map(f,r().split())
 if'0'<q:print'YNEOS'[a!=b::2]
 else:p[a]=b

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

download

return to the top page