I character is marked ( i . e . it was first or last character of some string ) then it should be visited in last dfs ( as for looping , graph should be strongly connected )
if ( mark [ i ] and ( not visit [ i ] ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT