Girls and Boys

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5565    Accepted Submission(s): 2481

Problem Description
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.

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, for n subjects.
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

Recommend
JGShining

嗯,看起来是个求最大独立集的题,而且还是个二分图.因为题里没说有Homosexuality,所以不会有奇环.不过图是用一般形式给出的算出来的匹配要除以2.

#include<stdio.h>
#include<string.h>
int n,m,match[];
bool visit[],G[][];
bool DFS(int k)
{
int t;
for (int i=;i<m;i++)
if (G[k][i] && !visit[i])
{
visit[i]=;
t=match[i];
match[i]=k;
if (t==- || DFS(t)) return true;
match[i]=t;
}
return false;
}
int Max_match()
{
int ans=;
memset(match,-,sizeof(match));
for (int i=;i<n;i++)
{
memset(visit,,sizeof(visit));
if (DFS(i)) ans++;
}
return ans;
}
int main()
{
int t,a,b,c;
while (scanf("%d",&t)!=EOF)
{
n=m=t;
memset(G,,sizeof(G));
while (t--)
{
scanf("%d: (%d)",&a,&b);
for (int i=;i<b;i++)
{
scanf("%d",&c);
G[a][c]=;
}
}
printf("%d\n",n-Max_match()/);
}
}

Girls and Boys的更多相关文章

  1. POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...

  2. hduoj-----(1068)Girls and Boys(二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. POJ Girls and Boys (最大独立点集)

                                                                Girls and Boys Time Limit: 5000MS   Memo ...

  4. poj 1466 Girls and Boys(二分图的最大独立集)

    http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submis ...

  5. hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. 网络流(最大独立点集):POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...

  7. Girls and Boys(匈牙利)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. (hdu step 6.3.2)Girls and Boys(比赛离开后几个人求不匹配,与邻接矩阵)

    称号: Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  9. HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. [Effective JavaScript 笔记]第23条:永远不要修改arguments对象

    arguments对象并不是标准的Array类型的实例.arguments对象不能直接调用Array方法. arguments对象的救星call方法 使得arguments可以品尝到数组方法的美味,知 ...

  2. [codeforces 528]A. Glass Carving

    [codeforces 528]A. Glass Carving 试题描述 Leonid wants to become a glass carver (the person who creates ...

  3. [BZOJ1061][Noi2008]志愿者招募

    [BZOJ1061][Noi2008]志愿者招募 试题描述 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难 题:为即将启动的奥运新项目招募一批短期志愿 ...

  4. OpenGL Vertex Array

    转载 http://blog.csdn.net/dreamcs/article/details/7699603

  5. function foo(){}、(function(){})、(function(){}())等函数区别分析

    前面一段时间,看到(function(){}),(function(){}())这些函数就犯晕,不知道它到底是什么意思,为什么函数外要加小括号,函数后要加小括号,加和不加到底有什么区别……一直犯迷糊, ...

  6. html 构建响应式网站之viewport的使用

    在网页代码的头部,加入一行viewport元标签 <!DOCTYPE html> <html lang="en"> <head> <met ...

  7. 基础知识《二》java的基本类型

    一.java基本数据类型 Java基本类型共有八种,基本类型可以分为三类,字符类型char,布尔类型boolean以及数值类型byte.short.int.long.float.double.数值类型 ...

  8. 【leetcode】Best Time to Buy and Sell Stock II

    Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...

  9. 61. 从1到n,共有n个数字,每个数字只出现一次。从中随机拿走一个数字x,请给出最快的方法,找到这个数字。如果随机拿走k(k>=2)个数字呢?[find k missing numbers from 1 to n]

    [本文链接] http://www.cnblogs.com/hellogiser/p/find-k-missing-numbers-from-1-to-n.html  [题目] 从1到n,共有n个数字 ...

  10. Android Studio 和 Gradle

    由于以前没做过什么java项目,在使用Android Studio时遇到了Gradle,真是一头雾水,决定总结一下. 具体的使用方法请参看:http://www.cnblogs.com/youxilu ...