#P4606. [SDOI2018] 战略游戏
[SDOI2018] 战略游戏
Description
With the NOI Qualifier approaching, carefree Xiao Q has no desire to practice problems. He coaxes Xiao C to slack off with him and play a strategic game.
The map of this strategic game consists of cities and undirected roads connecting these cities. From any city, it is always possible to reach any other city by following the roads.
Xiao C has already occupied at least two cities. Xiao Q may destroy one city not occupied by Xiao C, and simultaneously destroy all roads incident to that city. If, after destroying this city, there exist two cities and occupied by Xiao C such that starting from it is impossible to reach along the roads, then Xiao Q wins that round.
Xiao Q and Xiao C play rounds in total. In each round, you are given the set of cities occupied by Xiao C. You need to help Xiao Q count how many cities, if destroyed, would allow him to win that round.
Input Format
The first line contains a single integer , the number of test cases.
For each test case:
- The first line contains two integers and , the number of cities and the number of roads.
- The next lines each contain two integers and (), indicating there is a road between city and city . There may be multiple roads between the same pair of cities.
- The -th line contains an integer , the number of game rounds.
- The next lines: each line first gives an integer (), the number of cities occupied by Xiao C, followed by integers (), denoting the cities occupied by Xiao C.
Output Format
For each round, output a single line containing one integer: the number of cities whose destruction would allow Xiao Q to win that round.
2
7 6
1 2
1 3
2 4
2 5
3 6
3 7
3
2 1 2
3 2 3 4
4 4 5 6 7
6 6
1 2
1 3
2 3
1 4
2 5
3 6
4
3 1 2 3
3 1 2 6
3 1 5 6
3 4 5 6
0
1
3
0
1
2
3
Hint
Constraints
- .
- and .
- .
- For each test case, .
Subtasks
- Subtask 1 (30 points): For each test case, .
- Subtask 2 (45 points): For each query, .
- Subtask 3 (25 points): No additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号