4-cycle (Hard)
Time limit2sMemory limit1024 MB
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
vertices and undirected edges form a simple graph . In a simple graph, any two vertices are joined by at most one edge, and every edge connects two different vertices. The vertices of are numbered with positive integers from to .
A simple cycle of length in is a sequence of vertices that satisfies the following conditions.
- For every , an edge connects and in .
- For every , , and .
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 to .
- Append the second element to the end and delete the first element. That is, change to .
For example, the simple cycles and are the same simple cycle. Count the distinct simple cycles of length in the graph .
Input
The first line contains two integers () and (), separated by a space.
Each of the next lines contains two distinct vertices and (), separated by a space, which form an edge of .
No edge is given more than once.
Output
Print the number of distinct simple cycles of length in , modulo .
Note that is a prime number.