Reverse Delete Algorithm for Minimum Spanning Tree
Submissions: 631   Accuracy:


  Difficulty: Medium   Marks: 4

Reverse Delete algorithm is closely related to Kruskal’s algorithm. In Reverse Delete algorithm, we sort all edges in decreasing order of their weights. After sorting, we one by one pick edges in decreasing order. We include current picked edge if excluding current edge causes disconnection in current graph. The main idea is delete edge if its deletion does not lead to disconnection of graph. Your task is to print the value of total weight of Minimum Spanning Tree formed.

The first line of the input contains an integer 'T' denoting the number of test cases. Then 'T' test cases follow. Each test case consists of two lines. 
Description of  test cases is as follows:
The First line of each test case contains two integers 'V' and 'E'  which denotes the no of vertices and no of edges respectively.
The Second line of each test case contains 'E'  space separated triplets of m , n and w denoting that there is an edge from m to n and their weights.

Print the desired output in each line.



4 5
0 1 10 0 2 6 0 3 5 1 3 15 2 3 4 


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

Contributor: Saksham Raj Seth
Author: saksham seth

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

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

to report an issue on this page.