Professional Documents
Culture Documents
To keep track of how we got to (i, j) most profitably, we let w[i, j] be the value of j used to achieve the maximum
value of d[i, j]. These values are defined for 2 i n and 1 j n.
Thus we can run the following procedure:
1
Checkerboard(n, p)
for i = 1 to n do
set d[1, j] := 0
endfor
for i = 2to n do
forj = 1 to n do
set d[i, j] :=
if j > 1 then do
set d[i, j] := d[i 1, j 1] + p((i 1, j 1), (i, j))
set w[i, j] := j 1
endif
if d[i 1, j] + p((i 1, j), (i, j)) > d[i, j] then do
set d[i, j] := d[i 1, j] + p((i 1, j), (i, j))
set w[i, j] := j
endif
if j < n and d[i 1, j + 1] + p((i 1, j + 1), (i, j)) > d[i, j] then do
set d[i, j] := d[i 1, j + 1] + p((i 1, j + 1), (i, j))
set w[i, j] := j + 1
endif
endfor
endfor
return d and w
Once we fill in the d[i, j] table, the profit earned by the most profitable way to any square along the top row is
max1jn {d[n, j]}.
To actually compute the set of moves, we use the usual recursive backtracking method. This procedure prints
the squares visited, from row 1 to row n:
Print-Moves(w, i, j)
if i > 1 then
Print-Moves(w, i 1, w[i, j])
print (i,j)
2
each edge e. The flow f is acyclic: There is no cycle in G on which all arcs carry positive flow. The flow f
is also integer valued.
Now suppose we pick a specific arc e E and reduce its capacity by 1 unit. Show how to find a maximum
flow in the resulting capacitated graph in time O(m + n), where m is the number of edges in G and n is
the number of nodes.
We will assume that the flow f is integer-valued. Let e = (v, w). If the edge e is not saturated with flow, then
reducing its capacity by one unit does not cause a problem. So assume it is saturated.
We first reduce the flow on e to satisfy the capacity conditions. We now have to restore the capacity condition.
We construct a path from w to t such that all edges carry flow, and we reduce the flow by one unit on each of
these edges. We then do the same thing from v back to s. Note that because the flow f is acyclic, we do not
encounter any edge twice in this process, so all edges we traverse have their flow reduced by exactly one unit,
and the capacity condition is restored.
Let f 0 be the current flow. We have to decide whether f 0 is a maximum flow, or whether the flow value can be
increased. Since f was a maximum flow, and the value of f 0 is only one unit less than f , we attempt to find a
single augmenting path from s to t in the residual graph Gf 0 . If we fail to find one, then f 0 is maximal. Else, the
flow is augmented to have value at least that of f ; since the current flow network cannot have a larger maximum
flow value than the original one, this is a maximal flow.
4. Let G = (V, E) be a directed graph, with source s V , sink t V , and nonnegative arc capacities {ce }.
Give a polynomial time algorithm to decide whether G has a unique minimum cut (i.e. a cut of capacity
strictly less than that of all other cuts).
We first classify all nodes into three types:
upstream, that is, nodes v such that for all minimum cuts (A, B), we have v A;
downstream, that is, nodes v such that for all minimum cuts (A, B), we have v B;
central, that is, nodes v that neither upstream nor downstream, there is a minimum cut (A, B) such that
v A and a minimum cut (A0 , B 0 ) such that v B 0 .
Clearly, the minimum cut is unique if and only if there are no central nodes.
To check if there are central nodes, consider the cut (A , B ) found by performing breadth-first search on the
residual graph Gf at the end of a maximum flow algorithm. We claim that a node v is upstream if and only
if v A . Clearly, if v is upstream then it must belong to A ; since otherwise, it lies on the sink-side of the
minimum cut (A , B ). Conversely, suppose v A were not upstream. Then there would be a minimum cut
A0 , B 0 with v B 0 . Now since v A there is a path P in Gf from s to v. Since v B 0 , this path must have
an edge (u, w) with u A0 and w B 0 . But this is a contradiction, because no edge in the residual graph can
go from the source side to the sink side of any minimum cut.
A completely symmetric argument shows the following. Let B denote the nodes that can reach t in Gf , and let
A = V B . Then (A , B ) is a minimum cut, and a node w is downstream if and only if w B .
Thus our algorithm is to compute a maximum flow f , build Gf , and use breadth-first search to find the sets A
and B . These are the upstream and downstream nodes, respectively; the remaining nodes are central.