Logo
(追記) (追記ここまで)

20964번 - Sum of Distances 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB87373443.038%

문제

Bessie has a collection of connected, undirected graphs $G_1,G_2,\ldots,G_K$ (2ドル\le K\le 5\cdot 10^4$). For each 1ドル\le i\le K,ドル $G_i$ has exactly $N_i$ ($N_i\ge 2$) vertices labeled 1ドル\ldots N_i$ and $M_i$ ($M_i\ge N_i-1$) edges. Each $G_i$ may contain self-loops, but not multiple edges between the same pair of vertices.

Now Elsie creates a new undirected graph $G$ with $N_1\cdot N_2\cdots N_K$ vertices, each labeled by a $K$-tuple $(j_1,j_2,\ldots,j_K)$ where 1ドル\le j_i\le N_i$. In $G,ドル two vertices $(j_1,j_2,\ldots,j_K)$ and $(k_1,k_2,\ldots,k_K)$ are connected by an edge if for all 1ドル\le i\le K,ドル $j_i$ and $k_i$ are connected by an edge in $G_i$.

Define the distance between two vertices in $G$ 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,\ldots,1)$ and every vertex in the same component as it in $G,ドル modulo 10ドル^9+7$.

입력

The first line contains $K,ドル the number of graphs.

Each graph description starts with $N_i$ and $M_i$ on a single line, followed by $M_i$ edges.

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

출력

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

제한

예제 입력 1

2
2 1
1 2
4 4
1 2
2 3
3 4
4 1

예제 출력 1

4

$G$ contains 2ドル\cdot 4=8$ vertices, 4ドル$ of which are not connected to vertex $(1,1)$. There are 2ドル$ vertices that are distance 1ドル$ away from $(1,1)$ and 1ドル$ that is distance 2ドル$ away. So the answer is 2ドル\cdot 1+1\cdot 2=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

$G$ contains 4ドル\cdot 6\cdot 7=168$ vertices, all of which are connected to vertex $(1,1,1)$. The number of vertices that are distance $i$ away from $(1,1,1)$ for each $i\in [1,7]$ is given by the $i$-th element of the following array: $[4,23,28,36,40,24,12]$.

힌트

출처

Olympiad > USA Computing Olympiad > 2020-2021 Season > USACO 2021 January Contest > Platinum 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /