【ZJOI2007】 Matrix Game (Bipartite Graph Matching)

Topic description

Xiao Q is a very smart child. Besides chess, he also likes to play a computer puzzle game - the matrix game. Matrix games are played on an N*N black and white square (like chess, except that the colors are arbitrary). Two operations can be performed on this matrix at a time:

Row swap operation: select any two rows of the matrix and swap the two rows (that is, swap the colors of the corresponding grids)

Column exchange operation: select any two columns of the matrix and exchange the two columns (that is, exchange the color of the corresponding grid)

The goal of the game is to make the squares on the main diagonal (the line connecting the upper left corner to the lower right corner) of the square matrix all black through several operations.

For some levels, Xiao Q was so puzzled that he began to wonder if these levels were unsolvable at all! ! So Xiao Q decided to write a program to determine whether these levels have solutions.

 

Input and output format

Input format:

 

The first line contains an integer T representing the number of groups of data.

Next, it contains T groups of data. The first row of each group of data is an integer N, which represents the size of the square matrix; the next row of N is an N*N 01 matrix (0 means white, 1 means black).

 

Output format:

 

Contains T lines. For each set of data, if the level has a solution, output a line of Yes; otherwise, output a line of No.

 

Problem solving ideas

Reference: https://blog.csdn.net/baidu_36797646/article/details/53517050

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324930337&siteId=291194637