Poj 1466 (maximum vertex independence set)

Source: Internet
Author: User

By the Konig theorem, the minimum vertex overwrite = The maximum match

It can be found that in a bipartite graph, as long as the vertices in the minimum vertices overwrite set are removed, there is no edge between the remaining vertices, that is, the remaining vertices are the largest vertices independent set.

Then you can use (maximum vertex independence set) = (n-least vertex overwrite) = (n-maximum match)

 

Girls and boys
Time limit: 5000 Ms   Memory limit: 10000 K
Total submissions: 9325   Accepted: 4123

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 shocould write to standard output a line containing the result.

Sample Input

70: (3) 4 5 61: (2) 4 62: (0) 3: (0) 4: (2) 0 15: (1) 06: (2) 0 0 130: (2) 1 21: (1) 02: (1) 0

Sample output

 
52

Source

Southeastern Europe 2000

 

# Include <stdio. h> # Include < String . H> # Define N 1010 Int  N;  Int G [ 505 ] [ 505  ];  Int  CNT, pre [N];  Int  Mark [N], FRT [N];  Int  Save1 [N], save2 [N];  Int  Cnt1, cnt2;  Void Fdfs ( Int S, Int  F ){  If (F = 0 ) Save1 [cnt1 ++] = S;  Else Save2 [cnt2 ++] = S; Mark [s] = F;  For ( Int I = 0 ; I <n; I ++ ){  If (G [s] [I] = 0 ) Continue  ;  If (MARK [I] =- 1 ) Fdfs (I, f ^ 1  );}}  Int DFS ( Int  S ){  For ( Int I = 0 ; I <cnt2; I ++ ){  If (G [save1 [s] [save2 [I] = 0 | Mark [I] = 1 )Continue  ; Mark [I] = 1  ;  If (FRT [I] =- 1 | DFS (FRT [I]) {FRT [I] = S;  Return   1  ;}}  Return   0  ;}  Int Main (){  Int  Ans;  While (Scanf ( "  % D  " , & N )! = EOF) {cnt1 = Cnt2 = 0  ; Ans = 0  ; Memset (G,  0 , Sizeof  (G )); For ( Int I = 0 ; I <n; I ++ ){  Int  X, Y; scanf (  "  % D: (% d)  " , & X ,& Y );  //  If (y = 0) ans ++;              For ( Int J = 0 ; J <Y; j ++ ){  Int  TMP; scanf (  "  % D  " ,& TMP); G [I] [TMP] = G [TMP] [I] = 1  ;} Memset (mark, - 1 , Sizeof  (Mark ));  For (Int I = 0 ; I <n; I ++ ){  If (MARK [I]! =- 1 ) Continue  ; Fdfs (I,  0  );}  Int Sum = 0  ; Memset (FRT, - 1 , Sizeof (FRT ));  For ( Int I = 0 ; I <cnt1; I ++ ) {Memset (mark,  0 , Sizeof  (Mark); sum + = DFS (I);} printf (  "  % D \ n  " , N- Sum );}  Return  0  ;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.