This page is still under construction.

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

Boomerangs

Time limit2sMemory limit512 MB

Summary
Count pairs of adjacent edges in a connected graph whose removal disconnects the graph.
Level

Medium7 of 10

Topics
Graph, DFS, Implementation, Brute force
Solved
No attempts yet

Problem

You are given a graph GG. GG consists of NN vertices and MM edges and is connected. There are no self-loops, and no two edges share the same pair of endpoints.

If there exist vertices u,v,wu, v, w such that there is an edge between uu and vv and an edge between vv and ww, this pair of edges is called a boomerang.

Find the number of boomerangs such that removing the two edges of the boomerang leaves at least one pair of vertices that cannot reach each other along any sequence of edges.

Input

The first line gives NN and MM. (1≤N,M≤5×1051 \le N, M \le 5\times10^5)

The next MM lines give edge information as uu and vv, meaning there is an edge between vertex uu and vertex vv. (1≤u,v≤N1 \le u, v \le N, u≠vu \ne v)

Output

Print the number of boomerangs whose removal increases the number of connected components.

Examples1

  1. Example 1

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