CF Global Round 11 - One Billion Shades of Grey

Author: Benjamin Qi


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 cu,v\sum c_{u,v} subject to some inequalities of the form

Eq(u,v)=[cu,vxuxv].\text{Eq}(u,v)=\left[c_{u,v}\ge x_u-x_v\right].

Each cu,v0c_{u,v}\ge 0, and some xux_u are fixed (for tiles on the boundary) while the others are unbounded (if we ignore the constraint that each xi[1,109]x_i\in [1,10^9]). Essentially, to find we want a linear combination of these equations

Eq=au,vEq(u,v)\text{Eq}=\sum a_{u,v}\text{Eq}(u,v)

such that the following conditions are satisfied.

  • Each au,va_{u,v} corresponds to the flow on an edge of the min-cost flow graph, so these must be non-negative.
  • On the LHS of Eq\text{Eq}, no cu,vc_{u,v} has coefficient greater than one. This corresponds to au,v+av,u1a_{u,v}+a_{v,u}\le 1, meaning that the flow on each edge of the min-cost flow graph is at most 11.
  • The coefficients of each non-constant xux_u on the RHS of Eq\text{Eq} 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

c4,5x4x5c_{4,5}\ge x_4-x_5
c2,5x2x5c_{2,5}\ge x_2-x_5
c5,1x5x1c_{5,1}\ge x_5-x_1
c5,3x5x3c_{5,3}\ge x_5-x_3

and that xi=ix_i=i for each 1i41\le i\le 4 while x5x_5 is unbounded. What is the minimum possible value of

cu,v=c4,5+c2,5+c5,1+c5,3?\sum c_{u,v}=c_{4,5}+c_{2,5}+c_{5,1}+c_{5,3}?

Solution: In this case, the answer is 41=34-1=3. We can show that this is a lower bound by choosing

a4,5=1,a2,5=0,a5,1=1,a5,3=0.a_{4,5}=1, a_{2,5}=0, a_{5,1}=1, a_{5,3}=0.

Then we get the linear combination

Eq=a4,5[c4,5x4x5]+a5,1[c5,1x5x1]\text{Eq}=a_{4,5}\cdot \left[c_{4,5}\ge x_4-x_5\right]+a_{5,1}\cdot \left[c_{5,1}\ge x_5-x_1\right]
1[c4,5x4x5]+1[c5,1x5x1]1\cdot \left[c_{4,5}\ge x_4-x_5\right]+1\cdot \left[c_{5,1}\ge x_5-x_1\right]
Eq=[c4,5+c5,1x4x1].\text{Eq}=[c_{4,5}+c_{5,1}\ge x_4-x_1].

It follows that

cu,vc4,5+c5,1x4x1=41=3.\sum c_{u,v}\ge c_{4,5}+c_{5,1}\ge x_4-x_1=4-1=3.

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

  • Draw edges from 44 to 55, 22 to 55, 55 to 11, and 55 to 33 with cost 00.
  • Drawing edges from the source to vertex 44 with cost 44 and from the source to vertex 22 with cost 22.
  • Drawing edges from vertex 33 to the sink with cost 3-3 and from vertex 11 to the sink with cost 1-1.
  • Finding the maximum cost flow from the source to the sink. In this case, we just send one unit of flow from
source451sink.\text{source}\to 4\to 5\to 1\to \text{sink}.

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!