#P4897. 【模板】最小割树(Gomory-Hu Tree)
【模板】最小割树(Gomory-Hu Tree)
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
京公网安备 11011102002149号