Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 12811 | Accepted: 4005 |
Description
Input
Output
Sample Input
4 3 2 2 1 3 3
Sample Output
YES
Hint
Source
#include <stdio.h> #include <string.h> #include <math.h> int p[40][40] ;//0是空白点,-1不可选点,1左点集,2右点集 struct node1 { int x , y ; } l[1600]; struct node2 { int x , y ; } r[1600]; struct node { int x , y ; } d[1600] ; int nl , nr , n , m ; int link[1600] , temp[1600] ; int f(int x) { int i , j ; for(i = 0 ; i < nr ; i++) { if( temp[i] == 0 && fabs(l[x].x - r[i].x) + fabs( l[x].y - r[i].y ) == 1 ) { temp[i] = 1 ; if( link[i] == -1 || f( link[i] ) ) { link[i] = x ; return 1 ; } } } return 0 ; } int dd[][2] = { {0,-1},{0,1},{1,0},{-1,0} } ; void bfs(int i,int j) { int low = 0 , top = 1 , u , v ; d[0].x = i ; d[0].y = j ; p[i][j] = 1 ; while(low < top) { node mid = d[low++] ; for(i = 0 ; i < 4 ; i++) { u = mid.x + dd[i][0] ; v = mid.y + dd[i][1] ; if(u > 0 && u <= n && v > 0 && v <= m && p[u][v] == 0 ) { if( p[mid.x][mid.y] == 1 ) p[u][v] = 2 ; else p[u][v] = 1 ; d[top].x = u ; d[top++].y = v ; } } } } int main() { int t , tt , i , j , ans ; while(scanf("%d %d %d", &n, &m, &t)!=EOF) { tt = t ; memset(p,0,sizeof(p)); memset(link,-1,sizeof(link)); nl = 0 ; nr = 0 ; ans = 0 ; while(t--) { scanf("%d %d", &j, &i); p[i][j] = -1 ; } if( (n*m-tt)%2 ) { printf("NO\n"); continue ; } for(i = 1 ; i <= n ; i++) for(j = 1 ; j <= m ; j++) { if( p[i][j] == 0 ) { bfs(i,j); } } for(i = 1 ; i <= n ; i++) for(j = 1 ; j <= m ; j++) { if(p[i][j] == 1) { l[nl].x = i ; l[nl++].y = j ; } else if(p[i][j] == 2) { r[nr].x = i ; r[nr++].y = j ; } } for(i = 0 ; i < nl ; i++) { memset(temp,0,sizeof(temp)); if( f(i) ) { ans++ ; } } if( (n*m-tt) == ans*2 ) printf("YES\n"); else printf("NO\n"); } return 0; }