POJ 1466 HDU 1068 Girls and Boys (maximum independent set)

Source: Internet
Author: User

Girls and Boys
Time Limit: 5000MS Memory Limit: 10000K
Total Submissions: 11141 Accepted: 4983

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.

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

Source

Southeastern Europe 2000

A group of men and women engaged in ambiguous, seeking the largest set of elements to meet any two elements are not ambiguous.
Well, put out to eat dinner ~ ~:
/*=============================================================================## Author:liangshu-cbam # # QQ        : 756029571 # # School: Harbin Polytechnic University # # last modified:2015-08-27 17:19## filename:c.cpp## Description: # The people who is crazy enough to think they can change the world, is the ones who does! =============================================================================*/# #include <iostream> # include<sstream> #include <algorithm> #include <cstdio> #include <string.h> #include <c ctype> #include <string> #include <cmath> #include <vector> #include <stack> #includ e<queue> #include <map> #include <set> using namespace std;const int inf=800;    int N;int from[inf],tot;bool use[inf];vector<int>g[inf];bool Match (int x) {for (int i=0;i<g[x].size (); i++)            {if (!use[g[x][i]]) {use[g[x][i]]=1; if (from[g[x][i]]==-1| |                Match (From[g[x][i])) {from[g[x][i]]=x;            return 1; }}} return 0;}    int Hungary () {tot=0;    Memset (From,255,sizeof (from));        for (int. i=0;i<n;i++) {memset (use,0,sizeof (use));           if (Match (i)) {++tot; }} return tot;}    int main () {int x, y;        while (Cin>>n) {for (int i = 0; i < n; i++) {scanf ("%d: (%d)", &x, &y);            for (int j = 0; J < y; J + +) {int A;            scanf ("%d", &a);        G[x].push_back (a);        }} cout<<n-hungary ()/2<<endl;        for (int i = 0; i < INF; i++) {g[i].clear (); }} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 1466 HDU 1068 Girls and Boys (maximum independent set)

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.