Implement BFS and DFS
Implement build_graph(edges) (an undirected adjacency list, with each vertex's neighbour list sorted alphabetically for deterministic output), bfs(graph, start) and dfs(graph, start).
Read the number of edges, then that many "V1 V2" pairs, then a start vertex. Print the BFS order (space-separated), then the DFS order (space-separated).
main.py
Loading editor…
Console
Run your code to see output here.