For this question, my approach is to find all the cycles and push the weight of those cycles in a vector and sort it. Then according to the cost available, I’ll remove those edges, but my algorithm for finding the number of cycles and pushing them into a vector is not working.
code-https://ide.codingblocks.com/s/344355
Not able to code
hey @amanb25 try to code using this logic . your logic is incorrect.
This question can be solved greedily by finding Maximum Spanning Tree, MST(which can be found using minimum spanning tree algorithms). For the graph to remain connected, leave the edges of the MST. Now sort the remaining edges in the increasing order of their cost, remove the edges until the sum of costs of removed edges doesn’t exceed the allowed total cost.
Yes i did it that way but i still am not getting the right answer. code-https://ide.codingblocks.com/s/344417
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.