Rooks
Time limit1sMemory limit128 MB
Given an n x n 0/1 board, decide whether the number of ways to place n non-attacking rooks on the 1-cells is odd or even.
- Level
Medium7 of 10
- Topics
- Combinatorics, Math, Matrix, Bit manipulation
- Solved
- No attempts yet
Problem
You are given a square board of size in which some cells have been removed. You want to place rooks on the remaining cells so that all of the following rules hold:
- a rook may be placed only on a cell that has not been removed;
- each cell holds at most one rook;
- no two rooks attack each other, that is, every row and every column contains exactly one rook.
The number of valid placements can be enormous. For example, if no cell has been removed, the rooks can be arranged in ways. Your task is simpler: you only need to decide whether the number of valid placements is even or odd.
Write a program that reads the description of the boards and reports when the number of rook placements is even, or when it is odd.
Input
The first line contains a single integer , the number of boards (). The board descriptions follow.
Each board description starts with a line containing a single integer , the size of the board (). The next lines describe the rows of the board in order. Each such line contains integers from the set separated by single spaces, where means the cell has been removed and means a rook may be placed on that cell.
Output
Print integers, one per line. On the -th line print if the number of rook placements for the -th board is even, or if it is odd.
Hint

The illustration above shows every valid rook placement on one sample board of size .