Implement prototype(n: int, edges: list[tuple[int, int]], source: int) -> list[int | None] and solve with the same signature. Vertices are integers 0..n-1. Edges are undirected; self-loops and parallel edges are allowed. Return distances in vertex-index order, with source distance 0 and None for unreachable vertices.
Example: (3, [(0,1)], 0) returns [0,1,None].
Raise ValueError for n <= 0, an invalid source, or any endpoint outside 0..n-1. Prototype: enumerate simple paths. Final: use adjacency lists and BFS in O(V+E) time and space. Preserve the edge list, including on failure.
Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
Loading editor…
No results yet.
Complete the starter code, then run the checks.
Results and errors will appear here.