문제
Bessie has a collection of connected, undirected graphs (). For each , has exactly () vertices labeled and () edges. Each may contain self-loops, but not multiple edges between the same pair of vertices.
Now Elsie creates a new undirected graph with vertices, each labeled by a -tuple where . In , two vertices and are connected by an edge if for all , and are connected by an edge in .
Define the distance between two vertices in that lie in the same connected component to be the minimum number of edges along a path from one vertex to the other. Compute the sum of the distances between vertex and every vertex in the same component as it in , modulo .
입력
The first line contains , the number of graphs.
Each graph description starts with and on a single line, followed by edges.
Consecutive graphs are separated by newlines for readability. It is guaranteed that and .
출력
The sum of the distances between vertex and every vertex that is reachable from it, modulo .
예제 입력 1
2
2 1
1 2
4 4
1 2
2 3
3 4
4 1
예제 출력 1
4
예제 입력 2
3
4 4
1 2
2 3
3 1
3 4
6 5
1 2
2 3
3 4
4 5
5 6
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
예제 출력 2
706
점수
Test cases 3-4 satisfy .Test cases 5-10 satisfy .Test cases 11-20 satisfy no additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인