题目链接:http://acm.hdu.edu.cn/showproblem.php?
pid=1068
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int n; int used[505]; int link[505][505]; int boy[505]; int find(int x){ int i; for(i=0;i<n;i++){ if(!used[i]&&link[x][i]){ used[i]=1; if(boy[i]==0||find(boy[i])){ boy[i]=x; return true; } } } return false; } int main() { int all; int t,per,i,num; while(scanf("%d",&n)!=EOF){ memset(link,0,sizeof(link)); memset(boy,0,sizeof(boy)); all=0; for(i=0;i<n;i++){ scanf("%d: (%d)",&t,&num); while(num--){ scanf("%d",&per); link[t][per]=1; } } for(i=0;i<n;i++){ memset(used,0,sizeof(used)); all+=find(i); } printf("%d ",n-all/2); } return 0; }