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.

**Input:**

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.

**Output:**

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.

**Constraints:**

1<=T<=10

1<=n,e<=100

1<=w<=1000

**Example(To be used only for expected output):
Input**

2

3 3

1 2 5 2 3 3 1 3 1

2 1

1 2 5

4

5

Author: Shubham Joshi 1

mohamadhegazy97 | 57 |

ManojBharadhwaj | 49 |

bhatabhi554 | 48 |

adityak12 | 48 |

RaghavJindal | 47 |

blackshadows | 940 |

SunkyuHwang | 794 |

bently_nixon | 701 |

mb1973 | 491 |

Shaurya Khanna | 491 |

akhayrutdinov | 5043 |

Ibrahim Nash | 4967 |

blackshadows | 4640 |

Quandray | 4354 |

sanjay05 | 3668 |

Login to report an issue on this page.