### PROBLEM LINK:

**Author:** Sergey Nagin

**Tester:** Mahbub

**Editorialist:** Jingbo Shang

### DIFFICULTY:

Medium

### PREREQUISITES:

Matching, Gaussian Elimination

### PROBLEM:

Determine whether there is any perfect matching.

### EXPLANATION:

The problem setting is exactly same as the perfect matching. That is, find a subset of edges, there are no edges have common nodes and all nodes are covered by one edge. Since the graph is general, Blossom algorithm which can provide the maximum matching in O(**VE**) time is enough.

Here, I would like to introduce a simpler way to solve this problem. Of course, it is not some strange greedy algorithms which may passed because we can’t design cases for all wrong solutions (contestants are always creative :D). Anyway, let me introduce the simple solution – Tutte matrix. We can randomly choose the **X[i][j]**. Since we only need to check whether its determinant is zero, we can module all number during Gaussian Elimination (used to calculate the determinant) by a big prime, such as 10^9 + 7. Due to the randomness, we can solve this problem with a high probability. This solution is O(**V^3 log MOD**), where **MOD** is the big prime number we chosen. O(**log MOD**) is caused by the calculating the inverse or elimination by subtracting.

### AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.

Tester’s solution can be found here.