[Solution] Kirill and Company Codeforces Solution
Kirill lives on a connected undirected graph of vertices and edges at vertex . One fine evening he gathered friends, the -th friend lives at the vertex . So all friends are now in the vertex , the -th friend must get to his home to the vertex .
The evening is about to end and it is time to leave. It turned out that () of his friends have no cars, and they would have to walk if no one gives them a ride. One friend with a car can give a ride to any number of friends without cars, but only if he can give them a ride by driving along one of the shortest paths to his house.
For example, in the graph below, a friend from vertex can give a ride to friends from the following sets of vertices: , , , , , but can't give a ride to friend from vertex or a set .
Kirill wants as few friends as possible to have to walk. Help him find the minimum possible number.
The first line of input data contains an integer () — the number of test cases in the test.
The first line of the test case contains two integers and (, ) — the number of vertices and edges, respectively.
The next lines of the test case contain a description of the edges, two integers each and (, ) — indexes of vertices connected by an edge. It is guaranteed that there is at most one edge between any pair of vertices (i.e. no multiple edges in the graph).
Then follows line containing the number () — the number of Kirill's friends.
The next line of the test case contains integers: () — the vertices in which they live. Some vertices may be repeated.
The next line of the set contains the number () — the number of friends without cars.
The last line of each test case contains integers: (, ) — indexes of friends without cars.
It is guaranteed that the sum of over all cases does not exceed , as well as the sums of and .
Output lines, each of which contains the answer to the corresponding test case. As an answer, output a single integer — the minimum possible number of friends who will have to walk.
No comments:
Post a Comment