Can you help me optimizing my approach?
Religious People
are u willing to explain what are u trying to do in the question
I calculated no of a nodes of each connected graph and analayzing the problem i devised a formula:
Cost+=min(cost of temple+no of vertices-1(no of min edges),cost of temple*no of vertices)
I calculate no of nodes of one connected graph using dfs by taking counter c as global variable
The only problem is my approach is giving tle passing only one test case
u mean to say
cost of temple + ( no of component in that connected component-1) * cost of road
yes i wanted to say this
please refer this
i am trying to debug you code as well