Religiuos people

sir/mam,
my code pass only one test case what may be the error

If the temple cost is less then simply put temple in all cities else put one temple on each connected component.