CF Global Round 11 - One Billion Shades of Grey

Author: Benjamin Qi

Table of Contents


Edit on Github

Official Editorial

I assume that you've

This explanation is meant to clarify how the min-cost flow graph is derived.

Essentially, we want to find the best possible lower bound on the answer, which turns out to be equal to the answer by duality.

As the editorial mentions, you want to minimize subject to some inequalities of the form

Each , and some are fixed (for tiles on the boundary) while the others are unbounded (if we ignore the constraint that each ). Essentially, to find we want a linear combination of these equations

such that the following conditions are satisfied.

  • Each corresponds to the flow on an edge of the min-cost flow graph, so these must be non-negative.
  • On the LHS of , no has coefficient greater than one. This corresponds to , meaning that the flow on each edge of the min-cost flow graph is at most .
  • The coefficients of each non-constant on the RHS of are zero. This means that in the min-cost flow graph, each vertex (aside from the source and the sink) has the same in-flow as out-flow.
  • The constant on the right side is maximized (we want the best possible lower bound).

Example: (should hopefully clarify the above)

Suppose that

and that for each while is unbounded. What is the minimum possible value of

Solution: In this case, the answer is . We can show that this is a lower bound by choosing

Then we get the linear combination

It follows that

This corresponds to a min cost flow graph with vertices plus a source and a sink where all edges have capacity .

  • Draw edges from to , to , to , and to with cost .
  • Drawing edges from the source to vertex with cost and from the source to vertex with cost .
  • Drawing edges from vertex to the sink with cost and from vertex to the sink with cost .
  • Finding the maximum cost flow from the source to the sink. In this case, we just send one unit of flow from

In the original problem the edges go both ways (not just one way), but the idea is similar.

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!

Give Us Feedback on CF Global Round 11 - One Billion Shades of Grey!