#NEWLINE# def dfs( self , V , k , visited , marked , ret ) : #NEWLINE# #INDENT# '\n        dfs construct the ret while at the same time check acyclic\n\n        :return: whether it is acyclic\n        ' #NEWLINE# if ( k in marked ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# marked . add ( k ) #NEWLINE# for neighbor in V [ k ] : #NEWLINE# #INDENT# if ( neighbor not in visited ) : #NEWLINE# #INDENT# if ( not self . dfs ( V , neighbor , visited , marked , ret ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# marked . remove ( k ) #NEWLINE# visited . add ( k ) #NEWLINE# ret . append ( k ) #NEWLINE# return True