the key to union find is actaully two functions,
findandunion.unionis too simple to mentioned.findhas two implementations, the following ones also have path compressions:
the recursive one:
def find(x):
if x != father[x]:
father[x] = find(father[father[x]])
return father[x]
the procedure one:
def find(x):
while x != father[x]:
x = father[x]
father[x] = father[father[x]]
return father[x]