def find(node):
    """Find current canonical representative equivalent to node.

    Adjust the parent pointer of each node along the way to the root
    to point directly at the root for inverse-Ackerman-fast access.
    """
    if node.parent is None:
        return node
    root = node
    while root.parent is not None:
        root = root.parent
    parent = node
    while parent.parent is not root:
        grandparent = parent.parent
        parent.parent = root
        parent = grandparent
    return root
def find ( node ) : if node . parent is None : return node root = node while root . parent is not None : root = root . parent parent = node while parent . parent is not root : grandparent = parent . parent parent . parent = root parent = grandparent return root
Find current canonical representative equivalent to node.

    Adjust the parent pointer of each node along the way to the root
    to point directly at the root for inverse-Ackerman-fast access.