modifying bfs,dfs