标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3861 Accepted Submission(s): 2552
#include<stdio.h> #include<string.h> #define MAX 550 int n,m; int map[MAX][MAX],vis[MAX],str[MAX]; int find(int x) { int i; for(i=1;i<=n;i++) { if(map[x][i]&&!vis[i]) { vis[i]=1; if(str[i]==0||find(str[i])) { str[i]=x; return 1; } } } return 0; } int main() { int j,i,s,t,sum; int a,b; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); memset(map,0,sizeof(map)); memset(str,0,sizeof(str)); for(i=1;i<=m;i++) { scanf("%d%d",&a,&b); map[a][b]=1; } sum=0; for(i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(find(i)) sum++; } printf("%d\n",n-sum); } return 0; }
hdoj 1151 Air Raid【匈牙利算法+二分最小顶点覆盖】
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4668409.html