give cpp solution : Digital Village (Easy Version) time limit per test2 seconds memory…
- User
give cpp solution : Digital Village (Easy Version) time limit per test2 seconds memory limit per test256 megabytes This is the easy version of the problem. In the three versions, the constraints on n and m are different. You can make hacks only if all the versions of the problem are solved.
Pak Chanek is setting up internet connections for the village of Khuntien. The village can be represented as a connected simple graph with n houses and m internet cables connecting house ui and house vi , each with a latency of wi .
There are p houses that require internet. Pak Chanek can install servers in at most k of the houses. The houses that need internet will then be connected to one of the servers. However, since each cable has its latency, the latency experienced by house si requiring internet will be the maximum latency of the cables between that house and the server it is connected to.
For each k=1,2,…,n , help Pak Chanek determine the minimum total latency that can be achieved for all the houses requiring internet.
Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100 ). The description of the test cases follows.
The first line of each test case contains three integers n , m , p (2≤n≤400 ; n−1≤m≤400 ; 1≤p≤n ) — the number of houses, the number of cables and the number of houses that need internet.
The second line of each test case contains p integers s1,s2,…,sp (1≤si≤n ) — the houses that need internet. It is guaranteed that all elements of s are distinct.
The i -th of the next m lines of each test case contains three integers ui , vi , and wi (1≤ui<vi≤n ; 1≤wi≤109 ) — the internet cable connecting house ui and house vi with latency of wi . It is guaranteed that the given edges form a connected simple graph.
It is guaranteed that the sum of n3 and the sum of m3 do not exceed 108 .
Output For each test case, output n integers: the minimum total latency that can be achieved for all the houses requiring internet for each k=1,2,…,n .
Example Input 2 9 8 5 2 5 6 8 9 1 2 1 1 3 2 3 4 10 4 5 3 4 6 5 1 7 10 7 8 4 7 9 2 3 3 2 3 1 1 2 1 2 3 3 1 3 2 Output 34 19 9 4 0 0 0 0 0 2 0 0 Note In the first test case for k=3 , a possible optimal solution is to install servers at vertices 2 , 6 and 8 and obtain the following latency: latency(2)=0 latency(5)=max(3,5)=5 latency(6)=0 latency(8)=0 latency(9)=max(2,4)=4 So the total latency is 9 .
- Assistant