#P4120. [WC2012] 最小生成树
[WC2012] 最小生成树
Description
Given an undirected, weighted, connected graph , we want to modify edge weights so that its minimum spanning tree is unique. The unit costs to decrease and increase the weight of an edge by 1 are and , respectively, and the modified weights must be non-negative integers.
For example, for some graph , if after decreasing the weight of one edge by and increasing the weight of another edge by the minimum spanning tree becomes unique, then the total cost is . Compute the minimal total cost.
Input Format
Read from standard input.
The first line contains the string “” and a testdata ID.
The second line contains 4 positive integers , , , , denoting the number of vertices of , the number of edges, and the unit costs to decrease an edge weight by and to increase it by , respectively.
Each of the next lines contains 3 positive integers , , , indicating that there is an edge between vertices and with initial weight .
Vertices are numbered from to .
Output Format
Write to standard output.
Output a single line containing one integer, the minimal total cost. If no modification is needed, output .
mst 0
4 5 2 3
1 2 1
1 3 1
2 3 1
2 4 2
3 4 2
5
Hint
[Sample explanation]
After decreasing the weight of edge by and increasing the weight of edge by , the minimum spanning tree of graph becomes unique, and the total cost is minimal.
[Constraints]
Translated by ChatGPT 5
京公网安备 11011102002149号