#P4120. [WC2012] 最小生成树

[WC2012] 最小生成树

Description

Given an undirected, weighted, connected graph GG, 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 aa and bb, respectively, and the modified weights must be non-negative integers.

For example, for some graph GG, if after decreasing the weight of one edge by 33 and increasing the weight of another edge by 22 the minimum spanning tree becomes unique, then the total cost is 3a+2b3a+2b. Compute the minimal total cost.

Input Format

Read from standard input.

The first line contains the string “mstmst” and a testdata ID.

The second line contains 4 positive integers nn, mm, aa, bb, denoting the number of vertices of GG, the number of edges, and the unit costs to decrease an edge weight by 11 and to increase it by 11, respectively.

Each of the next mm lines contains 3 positive integers xx, yy, ww, indicating that there is an edge between vertices xx and yy with initial weight ww.

Vertices are numbered from 11 to nn.

Output Format

Write to standard output.

Output a single line containing one integer, the minimal total cost. If no modification is needed, output 00.

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 (2,4)(2,4) by 11 and increasing the weight of edge (2,3)(2,3) by 11, the minimum spanning tree of graph GG becomes unique, and the total cost is minimal.

[Constraints]

Test points 66~1010 download

Translated by ChatGPT 5