Sum of Distances
시간 제한: 1000ms메모리 제한: 512MB출처: USACO 2021 January PlatinumBOJ 20964
문제
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
출력
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
출력
706
코드를 제출하려면 로그인하세요.