bfs and dfs solution