#P10937. 車的放置

車的放置

Problem Description

Given a chessboard with NN rows and MM columns, it is known that some cells are forbidden to place pieces on.

Find the maximum number of rooks that can be placed on the board such that no two rooks can attack each other.

Each rook is placed in a cell, and its attack range is the same as the Chinese chess piece “車”.

Input Format

The first line contains three integers N,M,TN,M,T, where TT is the number of forbidden cells.

The next TT lines each contain two integers xx and yy, indicating that the cell at row xx and column yy is forbidden. Rows and columns are numbered starting from 11.

It is guaranteed that all forbidden cells are distinct.

Output Format

Output one integer, which is the answer.

8 8 0
8

Hint

Constraints: 1N,M2001 \le N,M \le 200.

Translated by ChatGPT 5