标签:
#include<cstdio> #include<cstring> #include<vector> #include<algorithm> #define pb push_back using namespace std; int n,m,k,link[105],vis[105],x[10005],y[10005]; bool G[105][105]; bool dfs(int u) { for(int i=1;i<=m;i++) { if(!vis[i]&&G[u][i]) { vis[i]=1; if(link[i]==-1||dfs(link[i])) { link[i]=u; return 1; } } } return 0; } int match() { int ans=0; memset(link,-1,sizeof(link)); for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(dfs(i))ans++; } return ans; } int main() { int kase=0; while(scanf("%d%d%d",&n,&m,&k)!=EOF) { int ans=0; memset(G,0,sizeof(G)); for(int i=0;i<k;i++) { scanf("%d%d",&x[i],&y[i]); G[x[i]][y[i]]=1; } int mres=match(); for(int i=0;i<k;i++) { G[x[i]][y[i]]=0; int res=match(); G[x[i]][y[i]]=1; if(res!=mres)ans++; } printf("Board %d have %d important blanks for %d chessmen.\n",++kase,ans,mres); } return 0; }
标签:
原文地址:http://www.cnblogs.com/homura/p/5874967.html