Under construction

Still being built. Things may change

4-cycle (Hard)

Time limit2sMemory limit1024 MB

Summary
Count the distinct simple cycles of length 4 in an undirected graph with up to 10^5 vertices and edges, output modulo 10^9+7.
Level

Medium6 of 10

Topics
Graph, Combinatorics, Hash map
Solved
No attempts yet

Problem

NN vertices and MM undirected edges form a simple graph GG. In a simple graph, any two vertices are joined by at most one edge, and every edge connects two different vertices. The vertices of GG are numbered with positive integers from 11 to NN.

A simple cycle of length LL in GG is a sequence of vertices (v0,v1,⋯ ,vL)\left( v_0,v_1,\cdots ,v_L \right) that satisfies the following conditions.

  • For every 0≤i<L0 \leq i < L, an edge connects viv_i and vi+1v_{i+1} in GG.
  • For every 0≤i<j<L0 \leq i < j < L, vi≠vjv_i \neq v_j, and vL=v0v_L = v_0.

Two simple cycles are treated as the same cycle if one can be turned into the other with these operations.

  • Reverse the sequence. That is, change (v0,v1,⋯ ,vL)\left( v_0,v_1,\cdots ,v_L \right) to (vL,⋯ ,v1,v0)\left( v_L,\cdots ,v_1,v_0 \right).
  • Append the second element to the end and delete the first element. That is, change (v0,v1,⋯ ,vL)\left( v_0,v_1,\cdots ,v_L \right) to (v1,⋯ ,vL,v1)\left( v_1,\cdots ,v_L,v_1 \right).

For example, the simple cycles (1,2,3,4,1)\left( 1,2,3,4,1 \right) and (2,1,4,3,2)\left( 2,1,4,3,2 \right) are the same simple cycle. Count the distinct simple cycles of length 44 in the graph GG.

Input

The first line contains two integers NN (2≤N≤1052 \leq N \leq 10^5) and MM (1≤M≤1051 \leq M \leq 10^5), separated by a space.

Each of the next MM lines contains two distinct vertices uu and vv (1≤u,v≤N1 \leq u,v \leq N), separated by a space, which form an edge of GG.

No edge is given more than once.

Output

Print the number of distinct simple cycles of length 44 in GG, modulo 109+710^9+7.

Note that 109+710^9+7 is a prime number.

Examples3

  1. Example 1

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

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

    Input
    6 15
    1 2
    1 3
    1 4
    1 5
    1 6
    2 3
    2 4
    2 5
    2 6
    3 4
    3 5
    3 6
    4 5
    4 6
    5 6
    
    Expected output
    45