This page is still under construction.

Parts of this page are still being built. What you see may change.

Duathlon

Time limit1sMemory limit1024 MB

Summary
Count ordered triples (s, c, f) of distinct vertices such that some simple path visits s, then c, then f, in an undirected graph with n up to 1e5.
Level

Hard8 of 10

Topics
Graph, BFS, DFS, Dynamic programming
Solved
No attempts yet

Problem

The street network of Byteburg has nn intersections and mm two-way street segments, and each segment joins two intersections. Byteburg was chosen to host the upcoming duathlon championship. The competition has two legs: a running leg, followed by a cycling leg.

The route is built like this. First pick three distinct intersections ss, cc and ff as the start, change and finish stations. Then build a route that starts at ss, goes through cc and ends at ff. For safety, the route visits each intersection at most once.

Before planning the route, the mayor wants to count the triples (s,c,f)(s, c, f) for which such a route exists. Compute that number.

Input

The first line contains the number of intersections nn and the number of streets mm (1≤n≤1051 \le n \le 10^5, 1≤m≤2×1051 \le m \le 2 \times 10^5). Each of the next mm lines describes one street with the numbers viv_i and uiu_i of the two intersections it joins (1≤vi,ui≤n1 \le v_i, u_i \le n, vi≠uiv_i \ne u_i). At most one street joins a given pair of intersections.

Output

Print the number of triples (s,c,f)(s, c, f) for which the route can be built.

Hint

In the first sample the 8 triples (s,c,f)(s, c, f) are (1,2,3)(1, 2, 3), (1,2,4)(1, 2, 4), (1,3,4)(1, 3, 4), (2,3,4)(2, 3, 4), (3,2,1)(3, 2, 1), (4,2,1)(4, 2, 1), (4,3,1)(4, 3, 1), (4,3,2)(4, 3, 2).

In the second sample the 14 triples (s,c,f)(s, c, f) are (1,2,3)(1, 2, 3), (1,2,4)(1, 2, 4), (1,3,4)(1, 3, 4), (1,4,3)(1, 4, 3), (2,3,4)(2, 3, 4), (2,4,3)(2, 4, 3), (3,2,1)(3, 2, 1), (3,2,4)(3, 2, 4), (3,4,1)(3, 4, 1), (3,4,2)(3, 4, 2), (4,2,1)(4, 2, 1), (4,2,3)(4, 2, 3), (4,3,1)(4, 3, 1), (4,3,2)(4, 3, 2).

Examples2

  1. Example 1

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

    Input
    4 4
    1 2
    2 3
    3 4
    4 2
    
    Expected output
    14