Girls and Boys

Source: Internet
Author: User

Girls and Boys
Time limit:20000/10000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 249 Accepted Submission (s): 163
Problem Description The second year of the University somebody started a study on the romantic relations between the Stude Nts. The relation "romantically involved" is defined between one girl and one boy. For the study reasons it was necessary to find out the the maximum set satisfying the condition:there was no and the students in T He set who has been "romantically involved". The result of the program was the number of students in such a set.

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 a integer number between 0 and n-1, for n subjects.
For each given data set, the program should write to standard output a line containing the result.
Output
Sample Input
70: (3) 4 5 61: (2) 4 62: (0) 3: (0) 4: (2) 0 15: (1) 06: (2) 0 130: (2) 1 21: (1) 02: (1) 0
Sample Output
52
Sourcesoutheastern Europe 2000
Recommendjgshining
/*first thought: give you a lattice, and then let you ask for the maximum number of connected graphs and find out the idea of a point # error: Test instructions didn't understand test instructions: Find out a maximum set makes any two people have no relationship because it is definitely the relationship between men and women (temporarily do not consider the problem of sexual orientation) so the whole diagram, Connected to the two-point chart, and then using the solution of the binary matching problem with the "Hungarian algorithm" requires the largest non-relational set, that is, the total number of vertices-the maximum number of matches*/#include<bits/stdc++.h>using namespacestd;intn,u,m,v;/*********************** binary matching template **************************/Const intmaxn=1010;intG[MAXN][MAXN];//the number is 0~n-1.intLINKER[MAXN];//Record the matching point of match point I whoBOOLUSED[MAXN];BOOLDfsintU//look back and see if we can make a match by breaking up{    intv;  for(v=0; v<n;v++)        if(g[u][v]&&!Used[v])//If there is this edge, and this side has not been used{Used[v]=true; if(linker[v]==-1|| DFS (Linker[v]))//If the point does not match and you can find a match, you can use this edge as the match point .{Linker[v]=u; return true; }            }      return false; }    intHungary ()//returns the maximum number of matches{    intres=0; intu; MEMSET (linker,-1,sizeof(linker));  for(u=0; u<n;u++) {memset (used,0,sizeof(used)); if(Dfs (U))//If this point has a matching pointres++; }     returnRes; }/*********************** binary matching template **************************/voidinit () {memset (g,0,sizeofg);}intMain () {//freopen ("C:\\users\\acer\\desktop\\in.txt", "R", stdin);     while(SCANF ("%d", &n)! =EOF)        {init ();  for(intI=0; i<n;i++) {scanf ("%d: (%d)",&u,&m);  for(intj=0; j<m;j++) {scanf ("%d",&v); G[U][V]=1; }        }//Building Map        intCur=Hungary (); //cout<<cur<<endl;printf"%d\n", n-cur/2); }    return 0;}

Girls and Boys

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.