Do DFS traversal of graph to detect cycle
visited = [ False ] * n NEW_LINE recur = [ False ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( visited [ i ] == False ) : NEW_LINE INDENT if ( isCycleRec ( i , adj , visited , recur ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT return True NEW_LINE