DFS =============================================== A vertex has three states in DFS: undiscovered, discovered, finished. The template for DFS: .. code:: none dfs(r, p, graph, x) where r is the reference of full solution, which you want to return finally. p is partial solution, which is element in r. graph is graph you want to traverse. x is used for termination condition of dfs.