http://acm.hdu.edu.cn/showproblem.php?pid=1281
View Code
1 //1281 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 const int N=110; 7 int g[N][N],n,m,u[N],v[N]; 8 int mat[N],vis[N]; 9 bool find(int u) 10 { 11 for(int v=1;v<=m;v++) 12 if(g[u][v] && !vis[v]) 13 { 14 vis[v]=1; 15 if(mat[v]==-1 || find(mat[v])) 16 { 17 mat[v]=u; 18 return 1; 19 } 20 } 21 return 0; 22 } 23 int maxmatch() 24 { 25 int cnt=0; 26 memset(mat,-1,sizeof(mat)); 27 for(int i=1;i<=n;i++) 28 { 29 memset(vis,0,sizeof(vis)); 30 if(find(i)) cnt++; 31 } 32 return cnt; 33 } 34 int main() 35 { 36 int k,C=0; 37 while(~scanf("%d%d%d",&n,&m,&k)) 38 { 39 memset(g,0,sizeof(g)); 40 for(int i=0;i<k;i++) 41 { 42 scanf("%d%d",&u[i],&v[i]); 43 g[u[i]][v[i]]=1; 44 } 45 int max=maxmatch(); 46 int cnt=0; 47 for(int i=0;i<k;i++) 48 { 49 g[u[i]][v[i]]=0; 50 if(maxmatch()<max) cnt++; 51 g[u[i]][v[i]]=1; 52 } 53 printf("Board %d have %d important blanks for %d chessmen.\n",++C,cnt,max); 54 } 55 return 0; 56 }