문제
Bessie has a collection of connected, undirected graphs
Now Elsie creates a new undirected graph
Define the distance between two vertices in
and every vertex in the same component as it in
.
입력
The first line contains
Each graph description starts with
Consecutive graphs are separated by newlines for readability. It is guaranteed that
출력
The sum of the distances between vertex
예제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
G
contains 4⋅6⋅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∈[1,7]
is given by the i
-th element of the following array: [4,23,28,36,40,24,12]
.