#P9896. MST problem
MST problem
MST problem
Problem Description
For a tree, we define its values as , where means the number of edges where weights . For example, if a tree with edges weight , its value equals . You're given a connected graph with vertices and edges. Try to find a spanning tree with minimal value. Output its value.
Input
The first line contains one integer (), representing the number of test cases. For each test case, the first line contains two integers (). The following lines, each line contains three integer (), represent an edge connecting vertex and , weights . It is guaranteed that the graph is connected and contains no self-loops (but may contain multi-edges). The number of test cases where or will not exceed .
Output
For each test case, output one integer, representing the minimal value of a spanning tree.
Sample Input
3
4 4
1 2 1
2 3 1
3 4 2
4 1 2
5 6
1 2 2
2 3 1
1 5 3
1 2 1
4 5 2
4 3 3
2 2
1 2 10
2 1 1
Sample Output
2
3
1
Source
2023“钉耙编程”中国大学生算法设计超级联赛(9)