Editorial for WC '17 Finals S2 - Cowmmunication Network
Submitting an official solution before solving the problem yourself is a bannable offence.
This problem can be represented as a graph, with
So, the only real difference is that we're allowed to use as many edges as we want, rather than exactly
The fact that some edges can have positive weights ends up not changing the solution too significantly. All such edges should clearly be used, even if they are not necessary for the graph's maximum spanning tree. Therefore, we can essentially find the maximum spanning tree as normal, and then additionally use all remaining edges with positive weights.
There are two standard algorithms for finding maximum spanning trees: Kruskal's and Prim's. Both can be slightly modified to solve this problem. Kruskal's works out very simply – when processing each edge (in non-increasing order of weight), it should still be used if it would connect two nodes which aren't yet connected, but it should also be used if its weight is positive. Prim's takes a bit more work, but one way to modify it is to keep track of exactly which edges get used in the maximum spanning tree, and then add on all unused positive-weight edges at the end. Both algorithms can be implemented in
Comments