Replace each vertex with it 's  corresponding parent except  the root vertex
if ( parent [ Vertices [ k ] ] != 0 ) : NEW_LINE INDENT Vertices [ k ] = parent [ Vertices [ k ] ] ; NEW_LINE DEDENT ans = True ; NEW_LINE flag = False NEW_LINE for k in range ( V ) : NEW_LINE