Give callers an explicit unreachable result without discarding valid zero-cost travel.
Zero and absence must remain different throughout the pipeline. A tuple (neighbor, 0) is an edge. A distance of zero means a route costs nothing, which can happen at the source or along a chain of zero-weight edges. Infinity means no route was found. Testing if distance would incorrectly reject every zero-cost destination.
The search implementations already support zero weights. This lesson adds an API boundary: return (cost, path) for a reachable target and (None, []) for an unreachable one. The annotation int | None makes that distinction visible to a caller without requiring them to understand our internal infinity marker. The separate reachable predicate receives a value from a validated search table, so it need only distinguish infinity from finite distances.
Consider dock-to-desk at cost zero and desk-to-yard at cost zero. Yard is reachable with path dock, desk, yard and total cost zero. A separate island has no path at all and gets the absent-cost marker. The fact that both zero and None are false in a condition is precisely why the API must compare explicitly.
A zero-cost cycle is also valid input. Strict improvement during relaxation prevents the same zero-cost route from being rescheduled forever. It also avoids replacing a settled parent with an equal-cost back edge. You do not need to modify Dijkstra, relaxation, or reconstruction; those completed definitions are supplied unchanged.
The wrapper validates the requested target's existence first. A missing target raises KeyError, while a present unreachable target returns the normal absence result. The search validates the source and all graph edges, including disconnected ones. Empty graphs therefore have no valid endpoint query.
This wrapper runs the heap search once and reconstructs at most one route. Time remains O(V + E log(E + 1)) plus O(L) reconstruction, with O(V + E) search space and O(L) returned path space. The final project will reuse one search for several destinations rather than repeating it unnecessarily.
Zero weight is a valid edge, not absence; relax only strict distance improvements.
(None, []) for a known but unreachable target.Edit main.py. Each numbered comment marks one checkpoint; replace its placeholder without changing the supplied code around it. Run shows the supplied probe, and Submit checks each task separately. You can submit after any step.