当前位置 : 主页 > 手机开发 > harmonyos >

poj 1466 Girls and Boys 最大独立集=n-最小覆盖点

来源:互联网 收集:自由互联 发布时间:2023-08-25
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


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


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; 
 
}

上一篇:线段树模板
下一篇:没有了
网友评论