The setup looks clean until you realize you need to seed the queue with all sources at distance zero simultaneously, not run separate BFS passes and take the min afterward.
Explain that multi-source BFS initializes the queue with all source nodes at distance 0, then performs standard BFS level by level. Emphasize that this computes shortest distances from the nearest source in O(V+E) time, and discuss handling disconnected nodes by assigning infinity or -1.
Pro tip: Mention that multi-source BFS is equivalent to adding a super-source connected to all sources with zero-weight edges, which justifies the correctness. Also, clarify how to handle duplicate sources and unreachable nodes to show attention to edge cases.
Confirm whether the graph is directed or undirected, weighted or unweighted, and how to represent unreachable nodes. Ask if sources can be repeated or if the graph is guaranteed connected.
Create a distance dictionary mapping each node to infinity (or -1), set all source nodes to 0, and initialize a queue with all sources. Use a visited set or rely on distance to avoid revisiting.
While the queue is not empty, pop a node, and for each neighbor not yet visited, set its distance to current distance + 1 and enqueue it. This ensures the first time a node is reached, it's via the shortest path from any source.
After BFS completes, return the dictionary. Nodes still at infinity (or -1) are unreachable from any source.
State that time complexity is O(V+E) and space is O(V). Discuss edge cases: empty graph, no sources, sources covering all nodes, and disconnected components.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.