Closed hairez closed 11 months ago
def find(self, a):
while a != self.par[a]:
a,self.par[a] = self.par[a], self.par[self.par[a]]
return a
@bjorn-martinsson mentioned that version 2 is actually faster, since all parents are mapped to the same parent which is the furthest away, which is faster in general.
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
self.parent[acopy], acopy = a, self.parent[acopy]
return a
I kinda disagree, this is never going to be used for ICPC because Python is too slow, this is for personal use where the ability to immediately have clarity is the most important thing.
It's three letters at each occurrence, at this point it is more practical to practice your typing.
One of many changes we want to make to the code on PyRival to make it more ICPC friendly. More specifically, it would be nice with shorter code, so more code could fit in the team reference document. Additionally, it would be easier to copy of by hand during a competition.