Problem - https://www.codechef.com/problems/GALACTIK
My code - https://www.codechef.com/viewsolution/18955508
I am trying to solve this using DFS .
I am finding all the connected components one by one .
Finding the minimum in that component such that it is >=0 and store it in answer vector. if there is no such minimum value(i.e. all values are -1) i break and just output -1.
Sort the vector answer.
ans = sum of min_values i.e (answer[i], 0<= i< answer.size() ) + (answer[0])*(connected_components -1)
Please help me to solve the problem … cant really find where i am wrong
EDIT :: I solved it . It found the bug. it was (sz-1) . it will be (sz-2). I made a mistake while typing