P28913 [洛谷] Giraffe Placement
提高+
题目描述

Problem Background

As is well known, in Western chess, we have rooks, knights, queens, bishops, and giraffes.

Problem Description

As shown in the figure, the "giraffe" in Western chess is similar to the horse in Chinese chess but attacks in a "目" shape and does not have the rule of "blocking the horse's leg" in Chinese chess. (Because giraffes don't have horse legs)

avatar

Given a chessboard of size $N * M$, some squares are forbidden to place chess pieces. Determine the maximum number of giraffes that can be placed on the board without attacking each other.

Input Format

The first line of input contains three positive integers $N$, $M$, and $K$. $K$ represents the number of squares where giraffes are forbidden to be placed.

Lines $2$ to $K+1$ each contain two integers $X_i, Y_i$, indicating the forbidden squares.

It is not guaranteed that the forbidden squares are distinct.

Output Format

A single line containing a positive integer, representing the maximum number of giraffes that can be placed.

Sample Input and Output

Sample Input #1

2 2 1
1 1

Sample Output #1

3

Sample Input #2

8 7 5
1 1
5 4
2 3
4 7
8 3

Sample Output #2

28

Notes

Important Hint: Consider the impact of the traversal order of the graph on the running speed.

For $10\%$ of the data, $1 ≤ N,M ≤ 5$

For $30\%$ of the data, $1 ≤ N,M ≤ 10$

For $60\%$ of the data, $1 ≤ N,M ≤ 50$

For $80\%$ of the data, $1 ≤ N,M ≤ 100$

For $100\%$ of the data, $1 ≤ N,M ≤ 200$

The data has been corrected, and some incorrect algorithms (including some solutions) will not pass this problem.

Thanks to @Alpha for pointing out the issue.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 2 1 1 1
样例输出
3