luogu#P4897. 【模板】最小割树(Gomory-Hu Tree)
【模板】最小割树(Gomory-Hu Tree)
Background
This is a template problem. Before solving it, please make sure you know Dinic or ISAP. If you brute-force your way through, I will ask you to smoke.
By convention, network flow problems do not allow testdata that hacks Dinic/ISAP, but they may hack EK. The testdata for this problem strictly follows the rule above.
Problem Description
Given an undirected connected graph with vertices and edges, labeled from to , answer multiple queries asking for the minimum cut between two vertices.
The minimum cut between two vertices is defined as follows: each edge in the original graph has a cost to cut it, and you need to make the two vertices disconnected with the minimum total cost.
Input Format
The first line contains two integers .
The next lines each contain three integers , indicating an undirected edge between and , with cutting cost .
The next line contains an integer , the number of queries.
The next lines each contain two integers . You need to compute the minimum cut between and .
Output Format
Output lines. Each line contains one integer, the answer to the corresponding query.
3 5
0 1 2
1 2 2
3 1 3
3 2 1
0 2 1
3
0 3
1 3
1 2
3
4
4
Hint
Constraints: , , , , and .
Translated by ChatGPT 5