poj 2446 Chessboard (二分图利用奇偶性匹配)

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 13176   Accepted: 4118

Description

Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of cards with size 1 * 2 to cover the board. However, she thinks it too easy to bob, so she makes some holes on the board (as shown in the figure below). 
poj 2446 Chessboard (二分图利用奇偶性匹配)

We call a grid, which doesn’t contain a hole, a normal grid. Bob has to follow the rules below: 
1. Any normal grid should be covered with exactly one card. 
2. One card should cover exactly 2 normal adjacent grids. 

Some examples are given in the figures below: 
poj 2446 Chessboard (二分图利用奇偶性匹配) 
A VALID solution.

poj 2446 Chessboard (二分图利用奇偶性匹配) 
An invalid solution, because the hole of red color is covered with a card.

poj 2446 Chessboard (二分图利用奇偶性匹配) 
An invalid solution, because there exists a grid, which is not covered.

Your task is to help Bob to decide whether or not the chessboard can be covered according to the rules above.

Input

There are 3 integers in the first line: m, n, k (0 < m, n <= 32, 0 <= K < m * n), the number of rows, column and holes. In the next k lines, there is a pair of integers (x, y) in each line, which represents a hole in the y-th row, the x-th column.

Output

If the board can be covered, output "YES". Otherwise, output "NO".

Sample Input

4 3 2
2 1
3 3

Sample Output

YES

Hint

poj 2446 Chessboard (二分图利用奇偶性匹配) 
A possible solution for the sample input.
给你一个棋盘,棋盘上有几个洞。要求你用一些1*2的卡片覆盖没有洞的区域,一个格子仅仅能有一张卡片覆盖。

看能否恰好覆盖。


二分匹配:利用二分匹配。两个能匹配的格子的坐标和必定奇偶性不同。利用这一点能够降低时间耗费。

!!
                    continue;
                memset(mark,0,sizeof(mark));
                ans+=find(i*m+j);
            }
        }
        //printf("%d
",ans);
        if(ans*2==n*m-k)
            printf("YES
");
        else
            printf("NO
");
    }
    return 0;
}