标签:
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9245 Accepted Submission(s): 4240
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<vector> 7 #define mem(x,y) memset(x,y,sizeof(x)) 8 using namespace std; 9 const int INF=0x3f3f3f3f; 10 const int MAXN=1010; 11 vector<int>vec[MAXN]; 12 int usd[MAXN],vis[MAXN]; 13 bool dfs(int x){ 14 for(int i=0;i<vec[x].size();i++){ 15 int v=vec[x][i]; 16 if(!vis[v]){ 17 vis[v]=1; 18 if(usd[v]==-1||dfs(usd[v])){ 19 usd[v]=x;return true; 20 } 21 } 22 } 23 return false; 24 } 25 int main(){ 26 int N,a,t; 27 while(~scanf("%d",&N)){ 28 for(int i=0;i<MAXN;i++)vec[i].clear(); 29 for(int i=0;i<N;i++){ 30 scanf("%*d: (%d)",&t); 31 // printf("t=%d\n",t); 32 while(t--){ 33 scanf("%d",&a); 34 vec[i].push_back(a); 35 } 36 }mem(usd,-1);mem(vis,0); 37 int ans=0; 38 for(int i=0;i<N;i++){ 39 mem(vis,0); 40 if(dfs(i))ans++; 41 } 42 printf("%d\n",N-ans/2); 43 } 44 return 0; 45 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4957526.html