4-Cycle (Easy)
InterviewTime limit2sMemory limit1024 MB
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
vertices and undirected edges form a simple graph . In a simple graph, each pair of vertices is joined by at most edge, and every edge connects two distinct vertices. The vertices of are numbered with positive integers at most .
A simple cycle of length in is a sequence of vertices that satisfies the following conditions.
- For every , an edge in connects and .
- For every , , and .
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 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 number of distinct simple cycles of length in .
Input
The first line contains (), the number of vertices of , and (), the number of edges, separated by a space.
From the second line, the next lines each contain two distinct vertices and () that form an edge of , 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 in , modulo .
Note that is a prime number.