Question
You are given an undirected graph with n nodes labeled 0..n-1 and an edge list. Each edge connects two nodes and is unweighted. Given a source node, return a list of length n where entry i is the shortest number of edges from the source to node i, or -1 if node i is unreachable. The source's own distance is 0. The graph may be disconnected and may contain multiple components; there are no self-loops and at most one edge between any pair.
bfs_distances(n: int, edges: list[list[int]], source: int) → list[int][4,[[0,1],[1,2],[2,3]],0]out[0,1,2,3]State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.