only 2 test case passed
what condition i have to check?
Religious people
Hi please tell me your approach first.
it would help to debug me faster
watch out this code
i have used the approach
if temp cost is less then each node has a temple build since road cost more
else
then u count no of independent component , for each independent component u calculate the no of nodes
supoose there are n node in one component among these n nodes 1 of them will have a temple and n-1 will incur road cost
hence the cost will be
for each indepedent component
totalCost += temple + (n-1) * cost of road
hey! sorry for late response
I used similar approach I count connected component and every connected component how much node it have and then for every connected component I just build a temple and for n-1 node build a road if temple cost is more than road cost.
I just change all the data type in long long int and then my code successfully submitted.