Table of Contents

## Kirill and Company solution codeforces

**Kirill and Company solution codeforces** – Kirill lives on a connected undirected graph of 𝑛n vertices and 𝑚m edges at vertex 11. One fine evening he gathered 𝑓f friends, the 𝑖i-th friend lives at the vertex ℎ𝑖hi. So all friends are now in the vertex 11, the 𝑖i-th friend must get to his home to the vertex ℎ𝑖hi.

The evening is about to end and it is time to leave. It turned out that 𝑘k (𝑘≤6k≤6) 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.

## [Solution] Kirill and Company solution codeforces

For example, in the graph below, a friend from vertex ℎ𝑖=5hi=5 can give a ride to friends from the following sets of vertices: [2,3][2,3], [2,4][2,4], [2][2], [3][3], [4][4], but can’t give a ride to friend from vertex 66 or a set [3,4][3,4].

## [Solution] Kirill and Company solution codeforces

The first line of input data contains an integer 𝑡t (1≤𝑡≤1031≤t≤103) — the number of test cases in the test.

The first line of the test case contains two integers 𝑛n and 𝑚m (2≤𝑛≤1042≤n≤104, 𝑛−1≤𝑚≤𝑚𝑖𝑛(104,n−1≤m≤min(104,𝑛⋅(𝑛−1)2n⋅(n−1)2))) — the number of vertices and edges, respectively.

The next 𝑚m lines of the test case contain a description of the edges, two integers each 𝑢u and 𝑣v (1≤𝑢,𝑣≤𝑛1≤u,v≤n, 𝑢≠𝑣u≠v) — 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 𝑓f (1≤𝑓≤1041≤f≤104) — the number of Kirill’s friends.

The next line of the test case contains 𝑓f integers: ℎ1,ℎ2,…,ℎ𝑓h1,h2,…,hf (2≤ℎ𝑖≤𝑛2≤hi≤n) — the vertices in which they live. Some vertices may be repeated.

The next line of the set contains the number 𝑘k (1≤𝑘≤𝑚𝑖𝑛(6,𝑓)1≤k≤min(6,f)) — the number of friends without cars.

The last line of each test case contains 𝑘k integers: 𝑝1,𝑝2,…,𝑝𝑘p1,p2,…,pk (1≤𝑝𝑖≤𝑓1≤pi≤f, 𝑝𝑖<𝑝𝑖+1pi<pi+1) — indexes of friends without cars.

It is guaranteed that the sum of 𝑛n over all cases does not exceed 104104, as well as the sums of 𝑚m and 𝑓f.

## [Solution] Kirill and Company solution codeforces

Output 𝑡t 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.

input

output

2 1 1

## [Solution] Kirill and Company solution codeforces

output

3 1 0

## [Solution] Kirill and Company solution codeforces

The first test case of the first example is explained in the statement.

In the second test case of the first example, two friends with cars live at vertex 55, one can give a ride to friends from vertices 22 and 33, and the second from vertex 44, only a friend from vertex 66 will have to walk.