POJ3228 Gold Transportation < MST >
Problem
Gold Transportation
Time Limit:
Memory Limit:
Description
Recently, a number of gold mines have been discovered in Zorroming State. To protect this treasure, we must transport this gold to the storehouses as quickly as possible. Suppose that the Zorroming State consists of N towns and there are M bidirectional roads among these towns. The gold mines are only discovered in parts of the towns, while the storehouses are also owned by parts of the towns. The storage of the gold mine and storehouse for each town is finite. The truck drivers in the Zorroming State are famous for their bad temper that they would not like to drive all the time and they need a bar and an inn available in the trip for a good rest. Therefore, your task is to minimize the maximum adjacent distance among all the possible transport routes on the condition that all the gold is safely transported to the storehouses.
Input
The input contains several test cases. For each case, the first line is integer . The second line is integers associated with the storage of the gold mine in every towns .The third line is also integers associated with the storage of the storehouses in every towns .Next is integer .Then M lines follow. Each line is three integers , and , means that there is a road between and for distance of . means end of the input.
Output
For each case, output the minimum of the maximum adjacent distance on the condition that all the gold has been transported to the storehouses or “No Solution”.
Sample Input
1 | 4 |
Sample Output
1 | 6 |
Translation
有个村庄,每个村庄有一个黄金矿和一个仓库,求一棵生成树森林,使得每棵生成树上的黄金矿都可被这棵生成树上的仓库存下,并且森林中最大边权最小。
标签:MST
Solution
一个简单的变形。
用从大到小贪心选边,每加一条边就判断森林中是否所有点所在的树都可以“自给自足”。总时间复杂度,即。
Code
1 |
|