working dfs and bfs