Distance Sum

Time limit4sMemory limit512 MB

Summary
Given a connected undirected unweighted graph with at most n+42 edges, compute the sum of shortest-path distances over all unordered vertex pairs.
Level

Hard8 of 10

Topics
Graph, BFS, Tree, Implementation
Solved
No attempts yet

Problem

You are given a connected undirected unweighted graph. The distance d(u,v)d(u, v) between two vertices uu and vv is the number of edges in the shortest path between them. Find the sum of d(u,v)d(u, v) over all unordered pairs of vertices (u,v)(u, v).

Input

The first line contains two integers nn and mm (2≤n≤1052 \le n \le 10^5 ; n−1≤m≤n+42n-1 \le m \le n+42), the number of vertices and the number of edges. The vertices are numbered from 11 to nn.

Each of the following mm lines contains two integers xix_i and yiy_i (1≤xi,yi≤n1 \le x_i, y_i \le n; xi≠yix_i \ne y_i), the endpoints of the ii-th edge.

There is at most one edge between every pair of vertices.

Output

Output a single integer: the sum of the distances between all unordered pairs of vertices in the graph.

Hint

In the first example, the distance between the four pairs of vertices connected by an edge is 1, and d(1,4)=d(2,4)=2d(1, 4) = d(2, 4) = 2.

Examples2

  1. Example 1

    Input
    4 4
    1 2
    2 3
    3 1
    3 4
    
    Expected output
    8
    
  2. Example 2

    Input
    7 10
    1 2
    2 6
    5 3
    5 4
    5 7
    3 6
    1 7
    5 1
    7 4
    4 1
    
    Expected output
    34