标签:
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10132 Accepted Submission(s):
4660
#include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<algorithm> using namespace std; int map[1005][1005],t; int link[1005],vis[1005]; int dfs(int x) { for(int i=0; i<t; i++) if(map[x][i]==1) if(vis[i]==0) { vis[i]=1; if(link[i]==-1||dfs(link[i])) { link[i]=x; return 1; } } return 0; } int solve() { int ans=0; memset(link,-1,sizeof(link)); for(int i=0; i<t; i++) { memset(vis,0,sizeof(vis)); if(dfs(i)) ans++; } return ans; } int main() { while(scanf("%d",&t)!=EOF) { memset(map,0,sizeof(map)); for(int i=0; i<t; i++) { int n,n1,num; scanf("%d: (%d)",&n1,&n); for(int j=0; j<n; j++) { scanf("%d",&num); map[i][num]=1; } } int ans=solve(); //cout<<ans<<endl; printf("%d\n",t-ans/2); } return 0; }
标签:
原文地址:http://www.cnblogs.com/jasonlixuetao/p/5564509.html