Part A: fill the advertiser's route, then pay to feed it
Running every route at its minimum costs 9, but it does not balance. Market receives 3 buses
and sends none, while Depot, Station and Harbour each send one more than they receive. The cheapest schedule costs 7:
| Route |
Buses |
Cost |
| Depot → Market |
4 |
12 |
| Market → Station |
3 |
6 |
| Station → Depot |
1 |
1 |
| Market → Harbour |
2 |
8 |
| Harbour → Depot |
3 |
−24 |
| Station → Harbour |
2 |
2 |
| Harbour → Market |
1 |
2 |
All 3 buses Harbour → Depot can take are run, and they earn 24. Getting them to Harbour costs
something: Station → Harbour is cheap but holds only 2, so the third bus comes Market → Harbour at
4. No other schedule costs 7 or less.
The prices Depot , Market , Station , Harbour prove it. Station → Depot has
reduced cost and runs at its minimum. Harbour → Depot has
and runs at its maximum. Every route strictly between its minimum and maximum has reduced cost 0.
Part B: a crowded pair of stops
The routes into include , whose minimum is 3. The routes out of
are and , and they hold only 1 each. So 3 buses must arrive every night and at
most 2 can leave, and no schedule exists. The complement proves the same thing from
the other side. No other set of stops proves it, and no single stop does.
Hoffman's circulation theorem (1960) says this kind of proof always exists. A schedule exists
if and only if, for every set of stops, the minimums of the routes entering add up to no
more than the maximums of the routes leaving . It is the max-flow min-cut theorem in other
clothes, as part C shows.
Part C: shift, augment, and read the prices off the end
Shift by the minimums. Write each route's flow as its minimum plus an extra amount between 0
and . Running every route at its minimum leaves each stop with a surplus
or a shortfall. What remains is an ordinary flow problem: route the surpluses to the shortfalls
using the extra room. Add a source joined to every stop with a surplus and a sink joined from
every stop with a shortfall. A schedule exists exactly when the maximum flow from source to sink
fills every one of those arcs. If it does not, the stops still reachable from the source in the
residual network form part B's proof. Their surplus is stuck behind full routes.
Cheapest paths. Start every paying route at its maximum and every other route at its
minimum. Then every arc of the residual network has a cost of at least zero. Successive shortest
paths keeps it that way: augment along a cheapest source–sink path each time, using Dijkstra's
algorithm with Johnson's potentials. At the end, the residual network has no cycle of negative
cost. Its shortest-path distances satisfy on every residual arc, and they
are the prices:
- A route below its maximum has a forward residual arc, so .
- A route above its minimum has a backward residual arc of cost , so .
That is exactly the condition the grader checks.
Why the prices prove it (part D). For any circulation , the prices cancel out:
. So every
circulation's cost equals its cost under the reduced costs . Under , a route with
is cheapest at its minimum and a route with at its maximum. Your schedule does
both, so no schedule costs less. For the converse: if a cheapest schedule had no prices, its
residual network would contain a cycle of negative cost. Pushing one bus round that cycle keeps
every contract and saves money, a contradiction.
Going further
- Linear programming. The prices are the dual variables of the minimum-cost circulation LP,
and the price condition is complementary slackness (LP Duality).
- Strongly polynomial algorithms. Successive shortest paths can take as many augmentations as
there are buses to move. Tardos gave the first algorithm whose running time does not depend on
the numbers at all, and Goldberg and Tarjan showed that cancelling cycles of minimum mean cost
is also strongly polynomial.
- Almost-linear time. In 2022, Chen, Kyng, Liu, Peng, Probst Gutenberg and Sachdeva solved
minimum-cost flow, and with it this problem, in time.
References
- A. J. Hoffman. Some recent applications of the theory of linear inequalities to extremal
combinatorial analysis. Proceedings of Symposia in Applied Mathematics 10, 1960.
- É. Tardos. A strongly polynomial minimum cost circulation algorithm. Combinatorica 5(3),
1985.
- A. V. Goldberg, R. E. Tarjan. Finding minimum-cost circulations by canceling negative cycles.
Journal of the ACM 36(4), 1989.
- L. Chen, R. Kyng, Y. P. Liu, R. Peng, M. Probst Gutenberg, S. Sachdeva. Maximum flow and
minimum-cost flow in almost-linear time. Proceedings of FOCS, 2022.