Description
Input
Output
Sample Input
4 3 2 2 1 3 3
Sample Output
YES
Hint
#include<iostream> #include<cstring> #include<cstdio> using namespace std; const long movex[4] = {0, 0, 1, -1}; const long movey[4] = {-1, 1, 0, 0}; const long N = 10010, M = 40010; long edge[N][5]; long l[N]; bool a[101][101]; bool b[N]; long n, m, k, nn; bool find(long x) { for(long i = 1; i <= edge[x][0]; i++) { long j= edge[x][i]; if (!b[j]) { b[j] = true; if((l[j] == 0)||(find(l[j]))) { l[j] = x; return true; } } } return false; } void init() { memset(a, true, sizeof(a)); for (long i = 1; i <= k; i++) { long x, y; scanf("%ld%ld", &x, &y); a[y][x] = false; } memset(edge, 0, sizeof(edge)); for (long i = 1; i <= n; i++) for (long j = 1; j <= m ; j++) { if (a[i][j]) { if ((i + j) % 2 == 0) { for (long k = 0; k < 4; k++) { long x = i + movex[k]; long y = j + movey[k]; if ((x <= 0)||(x > n)) continue; if ((y <= 0)||(y > m)) continue; if (a[x][y]) { long q1 = (i - 1) * m + j; long q2 = (x - 1) * m + y; edge[q1][0]++; edge[q1][edge[q1][0]] = q2; } } } } } } int main() { freopen("poj2446.in", "r", stdin); while(scanf("%ld%ld%ld", &n, &m, &k)!= EOF) { init(); long re = 0; memset(l, 0, sizeof(l)); for(long i = 1; i <= n; i++) for(long j = 1; j <= m; j++) { if ((i + j) % 2 == 0) { long tmp = (i - 1) * m + j; memset(b, 0, sizeof(b)); if ( find(tmp)) { re++; } } } if (re * 2 + k == n * m) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }