问题 E: Teyvat

内存限制:256 MB 时间限制:3 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

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 undirected connected graphundirected connected graph G=(V,E) of n points, m edges, where each vertex vV represents a location on the map, and each edge e=(vs,vt) represents a road from the point vs to vt.

Since Yoshinow2001 has a lot of Dendroculus did not take, so he will give you a total of Q queries, each query indicates that there are k vertexs a1,a2,,ak on the graph G, these vertexs need to take Dendroculus. He wants to know how many vertex pairs (S,T) satisfy 1STn so that any simple path from S to T passes through all vertexs in the set a1,,ak exactly once.

输入格式

Each test contains multiple test cases.The first line of input contains a single integer T(1T1×10^4)----the number of test cases.The description of test cases follows.

The first line contains three integers n,m,Q(1n5×10^5,1m,Q1×10^6) correspondingly represent the number of vertexs, the number of edges, the number of queries.

The following m lines contains two integers ui,vi(ui=vi) indicating an undirected edge between ui and vi. It is guaranteed that i,j:1i<jm satisfy (ui,vi)=(uj,vj).

The following Q lines. Each line begins with an integer k, representing the number of vertexs queried. Next k integers a1,,ak, representing the vertexs.

It is guaranteed that the sum of n for each test cases does not exceed 1.5×1061.5×106, the sum of mQi=1Qki for each test cases does not exceed 3×10^6.

输出格式

For each test case, output Q lines, where the i-th line contains an integer, representing the answer to the i-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 DON’T forget to add exit(0)DON’T forget to add exit(0); in the end of your main function, otherwise your code may get RE

输入样例 复制

1
3 3 3
1 3
3 2
1 2
1 1
2 2 3
3 1 2 3

输出样例 复制

3
1
0