def _dfs_cycle_detect(graph, node, path, visited_nodes):
visited_nodes.add(node)<EOL>for target in graph[node]:<EOL><INDENT>if target in path:<EOL><INDENT>return path + [target]<EOL><DEDENT>else:<EOL><INDENT>return _dfs_cycle_detect(graph, target, path + [target], visited_nodes)<EOL><DEDENT><DEDENT>return None<EOL>
search graph for cycle using DFS continuing from node
path contains the list of visited nodes currently on the stack
visited_nodes is the set of already visited nodes
:param graph:
:param node:
:param path:
:param visited_nodes:
:return: