Religious people


this code is giving me TLE in some test cases
approach- i have created a dummy node and connected all of them with the wt of cost of constructing a temple and then im finding MST

try using long long int insteadof int at all places in the code

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.

only A ans B are of 10^9 range so by only making return type and ans long long should do the work so why its giving TLE

Your prims algo is not accurate. You’ve put an if visited condition before going inside the for loop. If it doesn’t go inside the loop you’ll never be able to get out of the loop hence you’re facing a tle. Better put it inside the for loop .

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.