Implemented DFS.