#P9794. [NERC 2018] Distance Sum
[NERC 2018] Distance Sum
Background
Translated from Problem D of NERC 2018.
Problem Description
You are given a connected undirected graph with vertices and edges. Define the distance between and as the number of edges on the shortest path from to .
Now, compute .
Input Format
The first line contains two integers and , representing the number of vertices and the number of edges.
The next lines each contain two integers and , indicating that there is an edge between and .
It is guaranteed that there are no multiple edges or self-loops.
Output Format
Output .
4 4
1 2
2 3
3 1
3 4
8
7 10
1 2
2 6
5 3
5 4
5 7
3 6
1 7
5 1
7 4
4 1
34
Hint
For all testdata, it is guaranteed that , , , and .
The graph of Sample 1 is:

In it, , , , , , , and the total sum is .
Sample 2 is:

Translated by ChatGPT 5