💡 Religious People


my approach–
if cost to build temple <= repairing road then i am building temples in all the cities
and if this is not the case then i am counting no of trees present in forest of graph and then building one temple in each component and then repairing the roads for all the remaining cities…

but it is only passing one test case…

1
5 2 10 3
1 4
2 4

ur code does not handle situations line this when all nodes are not connected
like 5 is not connected to any
and also roads uptill 4 is given
ur code shows answer 22
it should be 36

@chhavibansal


i have modified this still not passing cases…

using same approach…i am unable to find mistake in my code

use long long int once

tried it getting TLE in one test case other are working fine…

1 Like

yr ekh bar code dekh le mera
there would be small flaw
i am not able to find any flaw