28/40
Part 5 of 7 · The answer and a limitLearn and do

A limit of k multiplies the work by k + 1, and k never needs to pass E

The table has V(k+1)V(k + 1) cells for VV junctions and a limit of kk. Every stretch is tried once per count. So the cost is O((V+E)(k+1))O((V + E)(k + 1)) time and O(V(k+1))O(V(k + 1)) memory.

A route can't ride more expert stretches than the park has, so kk never needs to pass EE, and this stays polynomial. A budget is different. One row per minute or per dollar is the coin-change lesson's pseudo-polynomial warning: a budget of a billion minutes is a table of a billion rows per junction.

In the editor, fill the inner loop of best_limited(below, order, start, exits, limit). It prints the best total for limits of 0, 1 and 2.