Routing Problem time limit: +Ms | Memory Limit:65535KB Difficulty:4
-
Describe
-
Nanyang Institute of Technology to carry out the transformation of power lines, the headmaster now asked designers to design a wiring method, the wiring method needs to meet the following conditions:
1, all the buildings are to power up.
2, the use of wire to spend the least
-
Input
-
The first line is an integer n indicating that there are n sets of test data. (n<5)
The first line of each set of test data is two integer v,e.
V indicates the total number of school buildings (v<=500)
In the subsequent E-line, there are three integers in each line a,b,c represents a and B if the build line costs C (c<=100). (If the two buildings do not specify the cost, it means that the direct connection between the two buildings is too expensive or impossible to connect)
In the subsequent 1 lines, there are v integers, of which the number of I represents the cost of wiring from the I building to the external power supply facility. (0<e<v* (V-1)/2)
(Building number starting from 1), due to safety issues, can only choose one building connected to the external power supply equipment.
Data guarantees that there is at least one scenario that satisfies the requirements.
-
Output
-
Each set of test data outputs a positive integer that represents the minimum cost of laying the line that meets the headmaster's requirements.
-
Sample input
-
14 61 2 102 3 103 1 101 4 12 4 13 4 11 3 5 6
-
Sample output
-
4
Code:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Nyoj 38 Cabling Problem "minimum spanning tree Kruskal"