Also reset the visited array
visited = [ False ] * len ( visited ) NEW_LINE for j in range ( level ) : NEW_LINE INDENT if curr_path [ j ] != - 1 : NEW_LINE INDENT visited [ curr_path [ j ] ] = True NEW_LINE DEDENT DEDENT