#P5934. [清华集训 2012] 最小生成树
[清华集训 2012] 最小生成树
Problem Description
Given a connected undirected graph with positive edge weights, where and . The vertices are numbered from to . Given three positive integers and , suppose we now add an edge with weight . What is the minimum number of edges that must be deleted so that this edge can appear in some minimum spanning tree, and can also appear in some maximum spanning tree?
Input Format
The first line contains two integers separated by spaces, which are and .
The next lines each contain three positive integers and , indicating that in graph there is an edge between and with weight .
The last line contains three integers separated by spaces, which are and .
The testdata guarantees that there are no self-loops in the graph.
Output Format
Output one line with one integer, indicating the minimum number of edges that need to be deleted.
3 2
3 2 1
1 2 3
1 2 2
1
Hint
Sample Explanation
We only need to delete edge . After deleting it and adding the new edge, the spanning tree of the graph becomes unique.
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5