Add 2nd dfs algorithm.