#P9833. Teyvat
Teyvat
Teyvat
Problem Description
Yoshinow2001 has not logged in the GenshinImpact for a long time, and there are many more Dendroculus on the map of the Teyvat continent. The map of the GenshinImpact can be seen as an of points, edges, where each vertex represents a location on the map, and each edge represents a road from the point to . Since Yoshinow2001 has a lot of Dendroculus did not take, so he will give you a total of queries, each query indicates that there are vertexs on the graph , these vertexs need to take Dendroculus. He wants to know how many vertex pairs satisfy so that any simple path from to passes through all vertexs in the set exactly once.
Input
Each test contains multiple test cases.The first line of input contains a single integer ----the number of test cases.The description of test cases follows. The first line contains three integers $n,m,Q(1\leq n\leq 5\times 10^5,1\leq m,Q\leq 1\times 10^6)$ correspondingly represent the number of vertexs, the number of edges, the number of queries. The following lines contains two integers indicating an undirected edge between and . It is guaranteed that satisfy . The following lines. Each line begins with an integer , representing the number of vertexs queried. Next integers , representing the vertexs. It is guaranteed that the sum of for each test cases does not exceed , the sum of for each test cases does not exceed .
Output
For each test case, output lines, where the -th line contains an integer, representing the answer to the -th query. Notes: In this problem, you may need more stack space to pass this problem. We suggest you to add the following code into your main function if you use C++.
int main() {
int size(512<<20); // 512M
__asm__ ( "movq %0, %%rsp\n"::"r"((char*)malloc(size)+size));
// YOUR CODE
...
exit(0);
}
And if you use the code above please ; in the end of your main function, otherwise your code may get RE.
Sample Input
1
3 3 3
1 3
3 2
1 2
1 1
2 2 3
3 1 2 3
Sample Output
3
1
0
Source
2023“钉耙编程”中国大学生算法设计超级联赛(4)