The input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description:
the number of students
the description of each student, in the following format
student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
or
student_identifier:(0)
The student_identifier is an integer number between 0 and n-1 (n <=500 ), for n subjects.
For each given data set, the program should write to standard output a line containing the result.
1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #include<cmath>
5 #include<cstring>
6 #include<queue>
7 #include<vector>
8 using namespace std;
9 const int mxn=800;
10 int n;
11 vector<int>mp[mxn];
12 int vis[mxn];
13 int mc[mxn];
14 int x;
15 inline int read(){
16 int x=0;
17 char ch=getchar();
18 while(ch<‘0‘||ch>‘9‘)ch=getchar();
19 while(ch>=‘0‘ && ch<=‘9‘){ x=x*10+ch-‘0‘;ch=getchar(); }
20 return x;
21 }
22 int dfs(int u){
23 for(int i=0;i<mp[u].size();i++){
24 int v=mp[u][i];
25 if(!vis[v]){
26 vis[v]=1;
27 if(mc[v]==-1 || dfs(mc[v])){
28 mc[v]=u;
29 return 1;
30 }
31 }
32 }
33 return 0;
34 }
35 int Maxmatch(){
36 int res=0;
37 memset(mc,-1,sizeof(mc));
38 int i;
39 for(i=0;i<n;i++){
40 {
41 memset(vis,0,sizeof(vis));
42 res+=dfs(i);
43 }
44 }
45 return res;
46 }
47 int main(){
48 while(scanf("%d",&n)!=EOF){
49 //read
50 for(int i=0;i<=n;i++) mp[i].clear();
51 for(int L=1;L<=n;L++){
52 int u,v;
53 u=read();
54 int i,j;
55 x=read();
56 for(i=0;i<x;i++){
57 v=read();
58 mp[u].push_back(v);
59 }
60 }
61 //read finished
62 int ans=Maxmatch();
63 printf("%d\n",n-ans/2);
64 }
65 return 0;
66 }