Minimum Spanning Tree
Submissions: 4633   Accuracy:


  Difficulty: Medium   Marks: 4
Associated Course(s):   Interview Preparation

Given a weighted, undirected and connected graph. The task is to find the sum of weights of  the edges of the Minimum Spanning Tree. You need to complete the function spanningTree() which takes a graph g as its argument and returns an integer denoting the sum of weights of the edges of the Minimum Spanning Tree.

The first line of input contains an integer T denoting the no of test cases . Then T test cases follow. The first line of each test case contains two integers n,e denoting the no of nodes and no of edges. Then in the next line are E*3 space separated values a b w where a,b denotes an edge from a to b and w is the weight of the edge.

For each test case in a new line print the sum of weights of  the edges of the Minimum Spanning Tree formed of the graph.


Example(To be used only for expected output):

3 3
1 2 5 2 3 3 1 3 1
2 1
1 2 5

Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: Shubham Joshi 1

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.