Counting Graphs
Time limit1sMemory limit512 MB
Given a connected undirected graph, count the graphs whose walk lengths from vertex 1 to every vertex match the original, modulo 1000000007.
- Level
Hard9 of 10
- Topics
- Graph, BFS, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
Bessie has a connected, undirected graph with vertices labeled to and edges. may contain self-loops (edges from a vertex back to itself), but no parallel edges (multiple edges between the same pair of endpoints).
Let be a boolean function that is true if there is a path from vertex to vertex that uses exactly edges, for every and . Otherwise it is false. If an edge is traversed several times, it is counted once for each traversal.
Elsie wants to copy Bessie. Specifically, she wants to build an undirected graph such that for all and .
Count the distinct graphs that Elsie can build, modulo . Like , may contain self-loops but no parallel edges. There are distinct graphs on labeled vertices in total.
Input
The first line contains , the number of test cases ().
Each test case starts with a line containing and (, ). The next lines each contain two integers and (), meaning that has an edge between and .
Test cases are separated by blank lines for readability. The sum of over all test cases does not exceed .
Output
For each test case, print the number of distinct modulo on its own line.