Police Chase

Revision en6, by ved_226, 2025-09-01 19:35:21

The "minimum number of streets to block" directly redirects us to Max Flow Min Cut Theorem.
It says the maximum flow we send from a source s to sink t is exactly equal to the capacity of the minimum cut that separates s from t. We have to divide the graph into two parts: one group containing the source and the other one containing the sink. A capacity of the cut is the sum of capacities of the edges going from the source's set to the sink's set.


My Approach

By using Edmonds-Karp Algorithm for max flow:

  • Starting with flow of 0
  • Repeatedly finding the Augmented Path from the source to the sink in the residual graph. It is just a simple path having the available capacity in the edge. (I considered the flow of the path to be 1).
  • Use BFS to find the augmented path, additionally calculate the minimum flow in the augmented path.
  • If the path is found and flow > 0 then add the path flow to maximum flow. Update the residual graph: decrease the capacity along the path and increase at opposite path. This finally leads to the maximum flow of the graph.

One thing we know is that the number of minimum streets to block = maximum flow we just calculated from the theorem.


To find the streets to cut:

  • Perform BFS/DFS over the residual graph from the source such that capacity of the edge is positive.
  • This detects the set of nodes which are with the source in it.
  • Now just iterate over this collection of nodes and find the other node reachable from these nodes in the original graph such that the child node is not in this set. These edges are our final streets which we have to cut.

Reference

My code

Tags graphs, maxflow

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en8 English ved_226 2025-09-01 19:44:07 78
en7 English ved_226 2025-09-01 19:36:13 0 (published)
en6 English ved_226 2025-09-01 19:35:21 67
en5 English ved_226 2025-09-01 19:34:28 230
en4 English ved_226 2025-09-01 19:30:33 21
en3 English ved_226 2025-09-01 19:27:47 1259
en2 English ved_226 2025-09-01 19:14:02 467 Tiny change: 'ut Theorem.**' -> 'ut Theorem**'
en1 English ved_226 2025-09-01 19:08:12 107 Initial revision (saved to drafts)