#P5632. 【模板】Stoer-Wagner
【模板】Stoer-Wagner
Description
Define the minimum cut of an undirected graph as follows: it is a set of edges such that removing these edges can make split into two connected components, and the sum of edge weights in this set is minimal.
Given an undirected graph , find its minimum cut.
Input Format
The first line contains two numbers , representing the number of vertices and the number of edges.
The next lines each contain three positive integers , indicating that there is an edge between and with weight .
Output Format
Output one line with one integer representing the minimum cut of . If the graph is disconnected, output 0.
4 6
1 2 5
1 3 1
2 4 1
3 4 2
2 3 1
1 4 2
4
Hint
For the first of the testdata, .
For the first of the testdata, .
For another of the testdata, the input is guaranteed to be a tree.
For another of the testdata, the input is guaranteed to be a chain.
For of the testdata, , and it is guaranteed that .
PS: If you want to submit “maximum flow / minimum cut tree”, just forget it.
Translated by ChatGPT 5
京公网安备 11011102002149号