QOJ.ac

QOJ

时间限制: 4 s 内存限制: 256 MB 总分: 100

#11263. Minimum Spanning Tree

统计

Given an undirected weighted connected graph $G$, we wish to modify the edge weights such that its minimum spanning tree (MST) is unique. The unit costs for decreasing and increasing the weight of an edge are $a$ and $b$, respectively, and the modified weights must be non-negative integers.

For example, for a graph $G$, if the MST becomes unique after decreasing the weight of one edge by $3$ and increasing the weight of another edge by $2$, the total cost is $3a + 2b$. Calculate the minimum total cost.

Input

The first line contains the data identifier; for the $i$-th test case, the first line contains the string "mst $i$".

The second line contains four positive integers $n, m, a, b$, representing the number of vertices in graph $G$, the number of edges, and the costs to decrease and increase an edge weight by $1$, respectively.

The following $m$ lines each contain three positive integers $x, y, w$, representing an edge between vertex $x$ and vertex $y$ with an initial weight $w$. Vertices are numbered from $1$ to $n$.

Output

Output a single line containing a non-negative integer, which is the required minimum cost. If no modification is needed (i.e., the MST of the graph is already unique), output $0$.

Examples

Input 1

mst 0
4 5 2 3
1 2 1
1 3 1
2 3 1
2 4 2
3 4 2

Output 1

5

Note 1

After decreasing the weight of edge $(2, 4)$ by $1$ and increasing the weight of edge $(2, 3)$ by $1$, the MST of graph $G$ becomes unique, and the total cost is minimized.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.