Religious people only two test cases pass

codeLink : https://ide.codingblocks.com/s/202469
above is my code , my approach basically involves making new temple in every city if construction cost is less than repair, if not so, making one temple in each city and connecting neighbours of that node via roads calculating the construction cost at the same time, using bfs

codeLink : https://ide.codingblocks.com/s/202469

please correct my code given above(mark modified wherever correction is made) and specify my error

please permit some time i am trying to debug the solution

Hi @Divya_321

ur code would fail the following test case
1
6 2 5 2
1 3
3 4
since u have not handled the case when the fewer paths are mentioned in the question most other remain unconnected
here the adjList would have no trace of node 2 , 5 , 6
they wont be considered for building the temple ( they are independent components)

refer this code:

or u wanna go by ur approach of using a map
here is the code :

here line 55-57 handle the case of independent components

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.