Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5642 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@sanskar94511 | 543 |

@akashverma4 | 335 |

@swastik8750 | 237 |

@nishunishuraj18 | 223 |

@nayan2709 | 211 |

@ajaybhardwaj1999 | 196 |

@surajmamgai | 193 |

@AnshikaPandey | 192 |

@gurshehzadsingh | 188 |

@shardul08 | 185 |

@Rajpra786 | 185 |

Complete Leaderboard |

Given a weighted, undirected and connected graph of V vertices and E edges. The task is to find the sum of weights of the edges of the Minimum Spanning Tree.

**Example 1:**

Input:Output:4Explanation: The Spanning Tree resulting in a weight of 4 is shown above.

**Example 2:**

Input:Output:5Explanation: Only one Spanning Tree is possible which has a weight of 5.

**Your task:**

Since this is a functional problem you don't have to worry about input, you just have to complete the function **spanningTree()** which takes number of vertices V** **and** **an adjacency matrix adj as input parameters and returns an integer denoting the sum of weights of the edges of the Minimum Spanning Tree. Here adj[i] contains a list of lists containing two integers where the first integer j denotes that there is an edge between i and j and second integer w denotes that the distance between edge i and j is w.

**Expected Time Complexity: **O(ElogV).

**Expected Auxiliary Space: **O(V^{2}).

**Constraints:**

2 ≤ V ≤ 1000

V-1 ≤ E ≤ (V*(V-1))/2

1 ≤ w ≤ 1000

Graph is connected and doesn't contain self loops & multiple edges.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Minimum Spanning Tree

...