Fast as Ryser
Time limit4sMemory limit512 MB
Sum c^|S| over all matchings S (edge sets with no shared vertex) in a graph with up to 36 vertices, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Graph, Bit manipulation, Dynamic programming, Divide and conquer
- Solved
- No attempts yet
Problem
After reading the paper Counting Perfect Matchings as Fast as Ryser, you learned how to count the number of perfect matchings in a general graph in . So you decided to write this problem to encourage people to read the paper and learn new technology.
You are given an undirected graph with vertices and edges, and also a constant . We define the weight of an edge set as follows:
- If there are two edges in set sharing common vertices, the weight is 0.
- Otherwise, the weight is . Note that the weight of an empty set is 1.
Compute the sum of the weight of all subsets of edges. The answer can be large, so output it modulo .
Input
The first line contains three integers , , (, , ). Each of the following lines contains two integers , (, ) indicating an undirected edge in the graph. All edges are distinct.
Output
Output one integer: the answer.