Maximum matching of POJ 1466 Girls and Boys binary graphs

Source: Internet
Author: User

Girls and Boys

Time limit:1 Sec Memory limit:256 MB

Topic Connection http://poj.org/problem?id=1466
Description

In the second, 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 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.

Inputthe 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 (n <=500), for n subjects. Output

For each given data set, the program should write to standard output a line containing the result.

Sample Input7
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) 0Sample OUTPUT5
2
HINT

Test instructions

Lets you find a collection of points so that no one in this collection likes each other

Exercises

This problem is the Hungarian algorithm, the largest matching simple deformation, the answer is

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 2001#defineMoD 10007#defineEPS 1e-9//const int INF=0X7FFFFFFF; //infinitely LargeConst intinf=0x3f3f3f3f;/**///**************************************************************************************inline ll read () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intMA[MAXN][MAXN];intVIS[MAXN];intMATCH[MAXN];intN,m;vector<int>E[MAXN];intDfsinta) {     for(intI=0; I<e[a].size (); i++)    {        if(vis[e[a][i]]==0) {Vis[e[a][i]]=1; if(match[e[a][i]]==-1||DFS (Match[e[a][i])) {Match[e[a][i]]=A; return 1; }        }    }    return 0;}intMain () { while(SCANF ("%d", &n)! =EOF) {memset (match,-1,sizeof(match));  for(intI=0; i<n;i++) e[i].clear (); M=N;  for(intI=0; i<m;i++)        {            intx, y; scanf ("%d: (%d)",&x,&y);  for(intj=0; j<y;j++)            {                intC=read ();            E[x].push_back (c); }        }        intans=0;  for(intI=0; i<m;i++) {memset (Vis,0,sizeof(VIS)); if(Dfs (i) = =1) ans++; } printf ("%d\n", n-ans/2); }}

Maximum matching of POJ 1466 Girls and Boys binary graphs

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.