#P9806. Counter Strike
Counter Strike
Counter Strike
Problem Description
SPY likes useful algorithms, while Markyyz always learns useless algorithms. Although they learn different type of algorithms, they both like a computer game called Counter Strike ("" for short, different from the game with the same name in reality). It is a two-player competition. One player acts as a terrorist ("" for short), responsible for planting bombs. The other one acts as a counter terrorist ("" for short), responsible for defusing bombs. At the start of each game, the system generates a bomb with a circuit in it. The circuit consists of hubs (numbered from to ) and wires. Each wire connects two different hubs, any two hubs could be directly or indirectly connected by wires, and no two hubs are directly connected by more than one wire. In other word, the circuit can be regarded as an undirected graph with vertices and edges, without multiple-edges or self-loops . The game is divided into three stages:
- Bomb planting stage: will receive activating components numbered from to . needs to select different hubs , and set the -th activating component on the -th hub.
- Bomb defusing stage: will receive a useful kit for free, and buy useless kits numbered from to . A useful kit can remove an arbitrary hub, while a useless kit can only remove a hub with an activating component in order, which means the -th useless kit can only remove the -th hub. Once a hub is removed, all wires directly connected to it will be cut off.
- Bomb activating stage: If any two
activating components
are connected directly or indirectly by wires, the bomb will be activated and will win. Otherwise, the bomb will be defused and will win.
For example, the picture above shows a bomb with a circuit consisting of hubs and wires. obtained activating components and set them on hub . can buy useless kits to remove the -th and the -th hub, then remove the -th hub with a useful kit.
Now Markyyz acts as , and SPY acts as . Markyyz has placed activating components . To save money for the future games, SPY wants to buy the minimum number of useless kits to defuse the bomb. Although SPY makes himself master of useful algorithms, he can't find the answer within the time complexity of . Can you help him to calculate the answer (in other word, the minimum value of for to win the game) ?
Input
The first line of the input contains an integer , indicating the number of test cases. In each test case: The first line contains three integers , indicating the number of hubs, the number of wires, and the number of activating components . The next lines, each line contains two integers , indicating a wire connected to the -th hub and the -th hub. The next line contains different integers . The -th activating component is set in the -th hub. It is guaranteed that in all test cases .
Output
You need to output a single integer in one line, indicating the minimum value of for to win the game.
Sample Input
1
19 27 6
1 2
1 3
2 4
3 4
2 5
4 5
5 6
5 8
6 7
6 8
8 7
8 9
7 9
7 10
9 10
5 11
11 12
12 13
13 14
14 12
11 15
11 16
16 17
16 18
17 18
17 19
18 19
16 17 2 18 12 9
Sample Output
2
Source
2023“钉耙编程”中国大学生算法设计超级联赛(2)