Module 8 · Graphs and Trees · Minimum Cost to Reach Destination in Time

Minimum cost to reach destination in time

Dijkstra on cost, with time carried along. The priority queue holds cities (index, cost, time) and poll() hands back the cheapest. A city polled after maxTime is skipped; the first time the destination is polled in time, its cost is the answer.

The number on a road is its time, the value under a city its passing fee. minTime holds the fastest arrival pushed so far for each city: a neighbour is pushed only when this way gets there sooner, because a dearer but faster way may be the only one that makes it in time. The text beside a city is that check.