<p class="pst">Description</p><div lang="en-US" class="ptx">In the second year of the university somebody started a study on the romantic relations between the students. The relation "romantically involved" is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been "romantically involved". The result of the program is the number of students in such a set.</div><p class="pst">Input</p><div lang="en-US" class="ptx">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.</div><p class="pst">Output</p><div lang="en-US" class="ptx">For each given data set, the program should write to standard output a line containing the result.</div><p class="pst">Sample Input</p><pre class="sio">7
0: (3) 4 5 6
1: (2) 4 6
2: (0)
3: (0)
4: (2) 0 1
5: (1) 0
6: (2) 0 1
3
0: (2) 1 2
1: (1) 0
2: (1) 0
Sample Output
5 2
/*
题意大概就是 有n个人 编号0~n-1,人和人之间有直接联系
问 最多可以有多少个没有直接联系的人
因为一共只有n个人 可以把n变为2*n
用匈牙利算法求最大匹配数x
最多没有直接联系的人为 n-x/2;
*/
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int map[510][510];
int mark[540];
int girl[510];
int n;
struct node
{
int next,to;
}node[50000];
int ans(int i)
{
int j;
for(j=0;j<n;j++)
{
if(mark[j]==0&&map[i][j]==1)
{
mark[j]=1;
if(girl[j]==-1||ans(girl[j]))
{
girl[j]=i;
return 1;
}
}
}
return 0;
}
int main()
{
int i,j,m,k;
while(scanf("%d",&n)!=EOF)
{
memset(map,0,sizeof(map));
memset(girl,-1,sizeof(girl));
for(k=1;k<=n;k++)
{
scanf("%d: (%d)",&i,&m);
while(m--)
{
scanf("%d",&j);
map[i][j]=1;
map[j][i]=1;
}
}
int x=0;
for(i=0;i<n;i++)
{
memset(mark,0,sizeof(mark));
x+=ans(i);
}
//printf("%d",x);
printf("%d\n",n-x/2);
}
}