Under construction

Still being built. Things may change

4-Cycle (Easy)

Interview

Time limit2sMemory limit1024 MB

Summary
Given a simple undirected graph with up to 1000 vertices and 1000 edges, count the distinct simple cycles of length 4 modulo 10^9+7.
Level

Medium4 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, each pair of vertices is joined by at most 11 edge, and every edge connects two distinct vertices. The vertices of GG are numbered with positive integers at most NN.

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

  • For every 0≤i<L0 \leq i < L, an edge in GG connects viv_i and vi+1v_{i+1}.
  • 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 regarded as the same cycle if one can be transformed into the other with the following operations.

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

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

Input

The first line contains NN (2≤N≤1 0002 \leq N \leq 1\,000), the number of vertices of GG, and MM (1≤M≤1 0001 \leq M \leq 1\,000), the number of edges, separated by a space.

From the second line, the next MM lines each contain two distinct vertices uu and vv (1≤u,v≤N1 \leq u, v \leq N) that form an edge of GG, separated by a space.

It is guaranteed that 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