添加链接描述
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int x,y;
int g[105][105];
int vis[105];
int linker[105];
bool dfs(int x){
for(int i=1;i<=m;i++){
if(g[x][i]&&!vis[i]){
vis[i]=1;
if(!linker[i]||dfs(linker[i])){
vis[i]=0;
linker[i]=x;
return 1;
}
}
}
return 0;
}
int hungary(){
int c=0;
memset(linker,0,sizeof linker);
memset(vis,0,sizeof vis);
for(int i=1;i<=n;i++){
if(dfs(i)) c++;
}
return c;
}
int main()
{
int num=1;
while(scanf("%d%d%d",&n,&m,&k)!=EOF){
memset(g,0,sizeof g);
for(int i=1;i<=k;i++){
scanf("%d%d",&x,&y);
g[x][y]=1;
}
int t=hungary();
int s=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(g[i][j]==1){
g[i][j]=0;
int r=hungary();
if(r<t) s++;
g[i][j]=1;
}
}
}
printf("Board %d have %d important blanks for %d chessmen.\n",num++,s,t);
}
return 0;
}