Minimum cost to connect cities
Given a city network having A nodes. The Roads of this city are damaged and you are asked to repair the roads.
Given a matrix B of size M x 3 which represents the road such that there is a road between B[i][0] and B[i][1] before the damage and cost of repairing this road is B[i][2]. you need to repair some of the roads with the minimum cost such that the city will get connected after repairing the roads. In other words, after repairing some of the the roads, every pair of the city will be reachable from one another.
Note:
No city was connected to itself before the roads were damaged.
Before the damage of roads, there is only one road between the given pair of roads.
Cities are Numbered from 1 to A.
The city network is connected before the roads are damaged.
Your solution will run on multiple test cases. If you are using global variables make sure to clear them.
Input Format
Output Format
Constraints
For Example
Last updated