Water supply network cost
You must supply water to n cities (1..n). For each city i you can either build a well in it at cost wells[i-1], or lay a bidirectional pipe between two cities given as [a, b, cost] to share water. A city has water if it has its own well or is connected by pipes to a city that has one. Return the minimum total cost to bring water to every city. wells has length n; there can be multiple pipes between the same pair.
Implement
min_water_cost(n: int, wells: list[int], pipes: list[list[int]]) → intExamples
in
[3,[1,2,2],[[1,2,1],[2,3,1]]]out3What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 35 min
solution.py
InputExpectedGot
[3,[1,2,2],[[1,2,1],[2,3,1]]]3not run yetsample