Perfect Matching

2

1 votes
Dynamic Programming, Algorithms, Hard
Problem

Given a bipartite graph having N vertices in each part and M edges, find the number of perfect matchings in it modulo 4.

Input format:
First line consists of a single integer T denoting the number of test cases.
First line of each case consists of two space separated integers denoting N and M.
Each of the following M lines consists of two space separated integers u and v, denoting that there is an edge between vertex numbered u on the left side and vertex numbered v on the right side. Vertices on each side are enumerated independently starting from 0.

Output format:
For each test case, print a single number in a new line - number of perfect matchings modulo 4

Constraints:
1T10
1N50
0MNN
0u,vN1

Sample Input
1
2 4
1 0
0 1
0 0
1 1
Sample Output
2
Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?