(False) faces
Time limit5sMemory limit512 MB
Given a 0/1 matrix of proposed left-right pairs, decide whether the number of perfect matchings is divisible by 4.
- Level
Medium7 of 10
- Topics
- Combinatorics, Math, Bit manipulation, Implementation
- Solved
- No attempts yet
Problem
The company is testing its brand-new face-recognition solution. The program is supposed to recognize people from their profile photos. To check that everything works, it is given a number of tests. Each test consists of photos of people: within a single test there is one left-profile photo and one right-profile photo of every person. The program pairs left profiles with right profiles, but it is still far from perfect, so sometimes several right profiles are linked to a single left profile (and vice versa).
A consistent reconstruction is an assignment of a distinct right profile to every left profile such that every matched pair is one that the program proposed.

The program's output (on the left) and four possible consistent reconstructions.
To test the program, every possible consistent reconstruction has to be verified. This must be done by humans, and the company has a team of four experts who have devoted their lives to face recognition. They will take the job under one condition: their shares of the work must be equal, i.e., the number of consistent reconstructions must be divisible by . Your task is to decide whether that is the case.
Input
The input contains several tests. The first line contains a positive integer , the number of tests. Then tests follow.
The first line of each test contains the number of people (). Then lines follow, each containing characters, each either or . The -th character of the -th line is if and only if the program pairs the -th left profile with the -th right profile.
Output
For each test, print a single line: YES if the number of reconstructions consistent with the program's pairing is divisible by , and NO otherwise.