11177 - Minimum Spanning Tree   

Description

Given a simple, undirected weighted graph G = (VEW), output the weight of its minimum spanning tree.

Input

The input includes multiple test cases. The first of the input is an integer T (T <= 1000) specifying the number of test cases. For each case, the first line contains two integers: the number of the node N and the number of the edges M. In the following M lines, each line contains three integers (sieici), 1 <= siei <= N, 1 <= ci <= 100, representing the indices of end vertices of an edge and the weight of the edge.

Case 1: 2 <= N <= 102, 1 <= M <= 103
Case 2: 2 <= N <= 103, 1 <= M <= 103
Case 3: 2 <= N <= 103, 1 <= M <= 104
Case 4: 2 <= N <= 103, 1 <= M <= 105

Output

For each case, output a single line that indicates the weight of the minimum spanning tree of the graph.

Sample Input  Download

Sample Output  Download

Tags




Discuss