Religious people failing testcases

i am not able to understand what testcases i am failing.
code link

@Daniyal-Farooque-446199309332205
Algorithm:
i am making connected components
then cost of building temple is less then simply build a temple in each node
else

eg. if( a component has 5 nodes => 1 of them has a temple made rest 4 will incur cost of road repair)
for no of independ component build 1 temple in each component
in the edgesInConnectedComponent vector i am storing the no of nodes each connected component has
so multiply the cost of road repair with no of nodes in each connected component

refer the code to get a better understanding

I have used the same logic as yours but couldn’t pass the test cases. Please correct my code i had send it in earlier post.

Hey @Daniyal-Farooque-446199309332205
Use long long instead of int considering range of costs

thanks it worked, i was not storing the answer so i thought i dont have to care about overflow so i totally forgot about the range of the costs.

1 Like