Cyber attack problem

sample test case is passing…but no test case is passing…
i’ve tried to di by MAXIMUM spanning tree…in which i have sorted in descending order weightwiswe
plzz help

Your else case is wrong in the iteration of edges code. You just need to save unused edges in a vector. Then sort it increasing order in weight. Then take first few edges till cost is less than money we have.

https://ide.codingblocks.com/s/187886 still not working

Logic is fine.
But you’re using int for money and cost. It should be long long.

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.

Using Kruskal’s method, we can sort edges in increasing order, and while performing spanning tree operation, mark the spanning-tree edge by changing its weight to zero. After constructing max spanning tree, iterate the graph from the back side and include weights s.t the current weight is not zero and adding the weight won’t exceed the overall cost.

Code