Assigning Heroes

0

0 votes
Medium
Problem

Professor Aizawa is now head of a Hero agency. His task is to allocate heroes in different cities. There are N cities and M roads, each of unit length. Also, one can reach any city from any other city using this network of roads.

There are K heroes to be allocated. In addition, there are X cities out of these N cities which are having a reinforcement center. Also, Heroes can only be allocated such that there is at most one Hero in a city. If a Hero is allocated to city C, he'll go to nearest reinforcement center in case of emergency. Let's call this reinforcement distance.

The task is to allocate these K heroes in such a way that they are in distinct cities and the sum of their reinforcement distances is minimum possible. Aizawa is feeling sleepy, so he has assigned this task to you. Print the min possible sum.

Eraserhead

 

Input Format:

First line contains T, number of test cases.

First line of each test case contains N, M, K and X.

Each of the next M lines of the test case contains U and V, denoting that there is road between cities U and V.

Next line of the test case contains X integers denoting the cities with reinforcement centers.

 

Output Format:

Print the required answer of each test case in separate lines.

 

Constraints:

1T5

1N105

N1M2105

1K,XN

 

Sample Input
1
5 5 3 1
1 2
1 4
2 3
3 4
3 5
2
Sample Output
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

City 1 is having reinforcement distance as 1, city 2 is having 0, city 3 is having 1, city 4 is 2, city 5 is 2. So, we choose cities 1, 2 and 3 with total distance as 2.

Editor Image

?