Does my logic for this question is corrct?

i am finding out all the bridges in the graph … then removing the bridges … now i will find the min lengths from the remaining connected components and stroing them in some list … then checking upto what sum of min lengths == s … that would be ans ??? :slight_smile:

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, s .

mam , cycle mei se min edge hatani hai …iss ques mei

agr mst bana diya toh min weight vali edge use ho jaygi

remaining ka weight toh zada hoga