I think it is related to mst but dont know how to apply to this problem.There should be
atleast one temple in every connected component but i am not sure how to calculate how many temples we should have in every connected compent?
Not clear how to solve
I don’t think this problem is related to MST.
we can try like this
if(A <= B) {
Then cost of building a temple is less than that of a road.
So we will build a temple in every city
There is no need to join two cities
} else {
Build a temple in each connected component and join connect these components by repairing roads because of cost of repairing is less than the cost of building a temple.
}
And yes MST will be used when you will connect these connected components by repairing the roads.
You will need to find the minimum number of roads to connect the connected component
If B < A you need to build only a single temple in a connected component. Why to build more than one
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.