Double the graph for a coupon
transcript
A trip may use one free leg. The route must remember the coupon. How do you track it?
Give every stop two states. Coupon unused, and coupon used. A normal leg stays in its layer. A free leg moves to the used layer.
Run Dijkstra on the doubled graph. A free leg costs nothing. The coupon can be used only once.
The target has two states. One means the coupon was never used. Take the cheaper of the two.
Thirty thousand stops become sixty thousand states. The legs triple to a hundred and eighty thousand. That is easy for Dijkstra.
Ask what the route must remember. Add that to the node. Then run the pass you know.
Write a slow twin that makes each leg free in turn. It takes the cheapest of all those trips. Compare both on small random graphs.
A trip uses at most one free leg. So two layers are enough. One holds unused trips, the other used trips. Each layer is a full copy of the stops and the legs.
Double the stops. Let a free leg switch layers. Full breakdown in the lecture.