Problems
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
.
Input
The first line contains
Each graph description starts with
Consecutive graphs are separated by newlines for readability. It is guaranteed that
Output
The sum of the distances between vertex
Example #1
2
2 1
1 2
4 4
1 2
2 3
3 4
4 1
4
Example #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]
.