Nyoj 38 Cabling Problem "minimum spanning tree Kruskal"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.