eolymp
bolt
Try our new interface for solving problems
Problems

Rook Attack

Rook Attack

You have been given a rows-by-cols chessboard, with a list of squares cut out. The list of cutouts will be given. This problem will involve placing rooks on a chessboard, so that they cannot attack each other. For a rook to attack a target piece, it must share the same row or column as the target. Rooks cannot be placed on cut out squares. The cut out squares do not affect where the rooks can attack. \InputFile Consists of multiple test cases. The first line of each test case contains three integers: the dimensions of the chessboard $rows$ and $cols~(1 \le rows, cols \le 300)$ and the number of cut out squares $cuts$. Next line gives the list of $(x, y)$ coordinates of cut out squares, delimited with a space. The list has a form $x_1~y_1~x_2~y_2~x_3~y_3 ... x_{cuts}~y_{cuts}$. It is known that $0 \le x_i \le rows - 1, 0 \le y_i \le cols - 1$. \OutputFile For each test case print in a separate line the maximum number of rooks that can be placed on the chessboard, such that no pair of rooks can attack each other.
Time limit 1 second
Memory limit 128 MiB
Input example #1
8 8 0

3 3 6
0 0 1 0 1 1 2 0 2 1 2 2
3 3 3
0 0 1 2 2 2
Output example #1
8
2
3

Example description: The second line is empty because the number of cut out squares in the chessboard of the first test case is 0