#507
Unrated
Sum of Distances
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie has a collection of connected, undirected graphs G1,G2,,GKG_1,G_2,\ldots,G_K (2K51042\le K\le 5\cdot 10^4). For each 1iK1\le i\le K, GiG_i has exactly NiN_i (Ni2N_i\ge 2) vertices labeled 1Ni1\ldots N_i and MiM_i (MiNi1M_i\ge N_i-1) edges. Each GiG_i may contain self-loops, but not multiple edges between the same pair of vertices.

Now Elsie creates a new undirected graph GG with N1N2NKN_1\cdot N_2\cdots N_K vertices, each labeled by a KK-tuple (j1,j2,,jK)(j_1,j_2,\ldots,j_K) where 1jiNi1\le j_i\le N_i. In GG, two vertices (j1,j2,,jK)(j_1,j_2,\ldots,j_K) and (k1,k2,,kK)(k_1,k_2,\ldots,k_K) are connected by an edge if for all 1iK1\le i\le K, jij_i and kik_i are connected by an edge in GiG_i.

Define the distance between two vertices in GG 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 (1,1,,1)(1,1,\ldots,1) and every vertex in the same component as it in GG, modulo 109+710^9+7.

입력

The first line contains KK, the number of graphs.

Each graph description starts with NiN_i and MiM_i on a single line, followed by MiM_i edges.

Consecutive graphs are separated by newlines for readability. It is guaranteed that Ni105\sum N_i\le 10^5 and Mi2105\sum M_i\le 2\cdot 10^5.

출력

The sum of the distances between vertex (1,1,,1)(1,1,\ldots,1) and every vertex that is reachable from it, modulo 109+710^9+7.

예제 입력 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 Ni300\prod N_i\le 300.Test cases 5-10 satisfy Ni300\sum N_i\le 300.Test cases 11-20 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.