
Boss
Boss: The Courier Network

Boss Fight!
Every passing test breaks a shield.
Storm season! The Guild's couriers carry lantern fuel between islands. The bridge-keepers have sent in their list of bridges, and every courier wants the fastest route, with every island on the way, before setting off.
You already have every piece:
- Bridge Routes: turn a list of bridges into a network, and
rebuild a route from a
prevdict. - Closest Island First: Dijkstra's algorithm for the fastest times.
Now put them together. The one new idea: whenever Dijkstra finds a
faster time to an island, also remember where it came from in
prev. At the end, walk prev back from the goal, just like in
Bridge Routes.
Assignment
Bridges are (from_island, to_island, minutes) tuples and are
one-way.
build_network(bridges): return a dict from each island to a list of(neighbor, minutes)tuples.shortest_times(network, start): return a dict of the fastest time to every reachable island (includingstart: 0), using Dijkstra.fastest_route(network, start, goal): return a tuple(minutes, path), wherepathis the list of islands fromstarttogoal. Follow these steps:- Run Dijkstra as in step 2, but whenever you improve
best[nxt], also setprev[nxt] = island. - If
goalis not inbest, return(None, []). - Otherwise rebuild the path from
prevand return(best[goal], path).
- Run Dijkstra as in step 2, but whenever you improve
Bridges are (from_island, to_island, minutes) tuples and are
one-way.
build_network(bridges): return a dict from each island to a list of(neighbor, minutes)tuples.shortest_times(network, start): return a dict of the fastest time to every reachable island (includingstart: 0), using Dijkstra.fastest_route(network, start, goal): return a tuple(minutes, path), wherepathis the list of islands fromstarttogoal. Follow these steps:- Run Dijkstra as in step 2, but whenever you improve
best[nxt], also setprev[nxt] = island. - If
goalis not inbest, return(None, []). - Otherwise rebuild the path from
prevand return(best[goal], path).
- Run Dijkstra as in step 2, but whenever you improve
main.py Python sleeping
Press Run to try your code, then Check to test it.