F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

City Planning

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 543    Accepted Submission(s): 273


Problem Description
Recently Bob received a job. It¡¯s to reform the city¡¯s transport system. Since the city has so many villages, and the transportation network is so large that the government want to reduce the roads number. The government has just choose some of them, your duty is to build a transportation network between them to make them link with each other directly or indirectly. Meanwhile you should use the least money. You may suppose that the initial transportation network makes up a tree.
 

Input
There are several test cases.
Each case starts with two integers n and m in a line. n stands for the number of all villages, m stands for the number of villages the government has chosen.( 0 < n < 1000, 0 < m <= n)
Then follow m integers in a line which means the chosen villages.
Then n - 1 lines follow, each line contains three integers a, b, c, indicating that between a and b there is a road available which costs c. (1 <= a, b <= n, a! = b, c <= 2000)
 

Output
For each test case, output the least money you need to use in a line.
 

Sample Input
6 3 2 3 4 1 2 3 1 3 1 3 6 4 2 5 4 2 4 2
 

Sample Output
6
 

Author
dandelion
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 12:14:08, Gzip enabled