Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
What if we model this problem as a graph problem?
A house is a node and a pipe is a weighted edge.
How to represent building wells in the graph model?
Add a virtual node, connect it to houses with edges weighted by the costs to build wells in these houses.
The problem is now reduced to a Minimum Spanning Tree problem.