Optimize Water Distribution in a Village
There are N homes in a village, we have to facilitate water supply in each of them. We can either build a well in a home or connect it with pipe to some different home already having water supply. More formally, we can either build a new well in the home or connect it with a pipeline to some different home which either has itβs own well or further gets water supply from a different home and so on. There is some cost associated with both building a new well and laying down a new pipeline. We have to supply water in all homes and minimise the total cost.
Input- First line contains an integer N, the number of homes. The next line contains N integers, the ith integer denotes the cost of building a well in that home. Next line contains an integer K, then K lines follows. Each of which contains 3 integers i, j and p. Which denotes the cost βpβ of laying down pipeline between homes i and j.
Output- Output a single integer - the minimum cost to supply water to all the homes
Last updated