poj 1466 Girls and Boys 最大独立集=n-最小覆盖点
2014-07-28 15:33
465 查看
Description
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.
Input
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.
Output
For each given data set, the program should write to standard output a line containing the result.
Sample Input
Sample Output
Source
Southeastern Europe 2000
#include<stdio.h>
#include<string.h>
bool Map[550][550];
bool Flag[550];
int Mark[550];
bool Find(int x,int n)
{
int i;
for(i=1;i<=n;i++)
{
if(!Map[x][i]||Flag[i])
continue;
Flag[i]=true;
if(!Mark[i]||Find(Mark[i],n))
{
Mark[i]=x;
return true;
}
}
return false;
}
int main()
{
int n;
int i,j;
int t;
int x,y;
int Count;
while(scanf("%d",&n)!=EOF)
{
memset(Map,false,sizeof(Map));
memset(Mark,0,sizeof(Mark));
for(i=1;i<=n;i++)
{
scanf("%d: ",&x);
scanf("(%d)",&t);
for(j=1;j<=t;j++)
{
scanf("%d",&y);
Map[x+1][y+1]=true;
}
}
Count=0;
for(i=1;i<=n;i++)
{
memset(Flag,false,sizeof(Flag));
if(Find(i,n))
Count++;
}
printf("%d\n",n-Count/2);
}
return 0;
}
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.
Input
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.
Output
For each given data set, the program should write to standard output a line containing the result.
Sample Input
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
Source
Southeastern Europe 2000
#include<stdio.h>
#include<string.h>
bool Map[550][550];
bool Flag[550];
int Mark[550];
bool Find(int x,int n)
{
int i;
for(i=1;i<=n;i++)
{
if(!Map[x][i]||Flag[i])
continue;
Flag[i]=true;
if(!Mark[i]||Find(Mark[i],n))
{
Mark[i]=x;
return true;
}
}
return false;
}
int main()
{
int n;
int i,j;
int t;
int x,y;
int Count;
while(scanf("%d",&n)!=EOF)
{
memset(Map,false,sizeof(Map));
memset(Mark,0,sizeof(Mark));
for(i=1;i<=n;i++)
{
scanf("%d: ",&x);
scanf("(%d)",&t);
for(j=1;j<=t;j++)
{
scanf("%d",&y);
Map[x+1][y+1]=true;
}
}
Count=0;
for(i=1;i<=n;i++)
{
memset(Flag,false,sizeof(Flag));
if(Find(i,n))
Count++;
}
printf("%d\n",n-Count/2);
}
return 0;
}
相关文章推荐
- POJ 1466 Girls and Boys 最大独立集 二分图匹配
- poj 1466 匈牙利(最大独立集)
- POJ 1466 二分图最大独立集.cpp
- POJ 1466 Girls and Boys 最大独立集
- POJ 1466 Girls and Boys (最大独立集Hungary)
- POJ 1466 Girls and Boys(二分图最大独立集)
- hdu 1466 Girls and Boys 最大点独立集=N-最大匹配
- POJ1466 二分图最大独立集[有陷阱的一道题]
- poj 1466 最大独立集
- POJ 1466 Girls and Boys(二分图匹配+拆点+最大独立集)
- poj 1466 Girls and Boys 最大独立集
- 最大独立集,二分图最大匹配 poj 1466
- poj 1466 Girls and Boys 二分图 最大独立集 (★★☆☆☆)
- POJ1466 二分图最大独立集[有陷阱的一道题]
- poj 3041 Asteroids 二分图的最大匹配==最小覆盖点。
- POJ 1466 最大独立集
- poj 1466(最大点独立集)
- poj 1466 二分图 最大独立集
- POJ 1466 Girls and Boys【最大点独立集】
- POJ-1466-Girls and Boys(二分图最大独立集)