Problem Summary
Given a undirected graph, a source and a sink, find the minimal number of vertices needed to be taken away so that the source and sink are disconnected.
Solution
This problem ask for the minimum cut of vertices. We can easily transform it to the classic minimum cut problem with a few steps:
- Spliting every vertex into two vertices, one in-point and one out-point.
- Add an edge with 1 capacity between each pair of in-point and out-point to the new graph.
- For every edge (i,j) in the original graph, add an edge with infinite capacity between the in-point of i and the out-point of j, and an edge with infinite capacity between the out-point of i and the in-point of j.
Then we just need to find the min cut of the new graph,i.e. the max flow. This can be easily done with Dinic’s algorithm.
Code
|
|