The Question
CodingOptimize Water Distribution in a Village
There are $n$ houses in a village. You want to supply water to all the houses by building wells and laying pipes.
For each house $i$, you can either build a well inside it directly with cost
wells[i-1], or pipe water from another house to it. The cost to lay a pipe between house $u$ and house $v$ is given by the array pipes where each pipes[j] = [house1, house2, cost] represents a bidirectional connection.
Return the minimum total cost to supply water to all houses.
Constraints:
- $1 \le n \le 10^4$
- wells.length == n
- $0 \le wells[i] \le 10^5$
- $1 \le pipes.length \le 10^4$
- $1 \le house1, house2 \le n$
- $0 \le cost \le 10^5$
- $house1 \neq house2$C++
Kruskal's Algorithm
MST
DSU