Finding the root of node i
def root ( arr , i ) : NEW_LINE INDENT while ( arr [ i ] != i ) : NEW_LINE INDENT arr [ i ] = arr [ arr [ i ] ] NEW_LINE i = arr [ i ] NEW_LINE DEDENT return i NEW_LINE DEDENT