COMP3121-Assignment 4 Solutions
COMP3121-Assignment 4 Solutions
Assignment 4 Solutions
Hint: Combine a binary search with a max flow. By sorting you can assume
that di form an increasing sequence. Fix i and consider only roads which
take ≤ di hours to travel from a warehouse to the corresponding shop and
use max flow to see if they are enough to obtain a matching of warehouses
with shops which is of size n. Use a binary search on i to find the smallest
di which meets the requirements.
1
bipartite graph Gi with warehouses wj as the left side of the partition and
with shops sj (1 ≤ j ≤ n). Connect all warehouses with all shops which are
within travel distance times di . Use max flow to see if such bipartite graph
has a perfect maximum matching of size n. Use a binary search to find
the smallest i such that graph Gi has a matching of size n, i.e., a matching
in which every warehouse has been matched with a shop, so that different
warehouses are assigned different shops.
4. Use max flow algorithm to solve the following problem. You are given an
n×n chess board with k white bishops on the board at the given cells (ai , bi ),
(1 ≤ ai , bi ≤ n, 1 ≤ i ≤ k). You have to determine the largest number of
black rooks which you can place on the board so that no two rooks are in
the same row or in the same column or are under the attack of any of the k
bishops (recall that bishops go diagonally).(25 pts)
Solution: Construct a bipartite graph with n left side vertices representing
rows of the board and n right side vertices representing columns. Connect
with directed edges of capacity one every left side vertex i with all right side
2
vertices j which satisfy the property that the cell (i, j) of the board is not
under attack from one of the bishops. Add a super source and connect it
with all left vertices with edges of capacity one; add a super sink and connect
every right side vertex with such super sink with edges of capacity one. Find
max flow; if the flow equals n then the problem has a solution. The rooks
should be placed on cells (i, j) which correspond to edges with flow in them.