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

mmm2

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 63365/63365 K (Java/Others)
Total Submission(s): 110    Accepted Submission(s): 8


Problem Description
It's a well-known fact that MMM, the greatest general in history, loves traveling.
This time she is setting off to Tianjin, a city famous for stuffed-bun, with her MMM Army. Tianjin is a city with N sites. And N sites are divided into several areas. Each site belongs to exactly one area. For each area, the number of sites and the number of street connected them are equal, and each pair of sites belong to the same area, there existed at least one simple path going from one site to the other. For each pair of sites belong to different area, no streets will connect them. The deliciousness of buns in the bakehouse on the i-th site is evaluated as an integer Wi. As MMM wants to maintain Bureaucratic Government (BG for short) to her army, she would invite them to every bakehouse on their way. But there is one problem: MMM hates to visit a site twice because 2 is an ominous number to her. However, they could choose to take the subway if in need. The subway in Tianjin is well developed so they can transport from any sites to any other sites conveniently even if when they are not connected by the streets. But MMM will feel carsick if they take the subway K times or more.
Now the question is, what's the maximum total deliciousness can MMM reach without carsickness? Note that with the convenient subway the MMM Army can start and end their journey in any site.
 

Input
The first line of input consist of one integer T which means T cases will follow (1¡ÜT¡Ü15).
Then follow T cases, each case begin with two integers N, K (1¡Ü N ¡Ü 50000, 1¡Ü K ¡Ü10).
The following line contains N integer Wi, |Wi| ¡Ü 10^6.
Then N line follow, each line contains two integer u, v. mean there is a street between site u and site v. 1 ¡Ü u, v ¡Ü N
 

Output
Just a line contains the maximum total deliciousness
 

Sample Input
1 9 3 -2 -10 3 15 11 1 10 10 -3 1 2 1 3 2 3 2 4 2 5 5 6 3 7 8 9 9 8
 

Sample Output
40
 

Hint

mmm's army start at city 6, and walk to city 4,the path is 6->5->2->4. total deliciousness is 1+11+(-10)+15=17.
then take subway to city 3, and then walk to city 7,the path is 3->7. total deliciousness is 3+10=13.
then take subway to city 8, and end their travel at city 8.total deliciousness is 10,
so the answer is 17+13+10=40.

 

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-04-27 10:24:57, Gzip enabled