Religious peple : code not working

What wrong in this code.


Logic is correct I thing but still its passing only two testcases.
What I am doing is if cost of making temple is less then building roads then i am just returning multiplication of cost of temple and no of nodes otherwise for each component I am calculating cost of 1 temple road contruction cost for all nodes in that component.