Girls and Boys
Time Limit: 5000MS   Memory Limit: 10000K
Total Submissions: 12192   Accepted: 5454

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 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
【分析】给出一些有关系的男女们,问最多有多少人之间没有关系。那就是求最大独立点集了,最大独立点集==顶点总数-匹配数。
由于此题我是两两匹配了两次,所以除以二。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
#define inf 0x7fffffff
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = ;
const int M = ;
int read() {
int x=,f=;
char c=getchar();
while(c<''||c>'') {
if(c=='-')f=-;
c=getchar();
}
while(c>=''&&c<='') {
x=x*+c-'';
c=getchar();
}
return x*f;
}
int n,k,cnt;
int mp[N][N],vis[N],link[N];
int head[N],x[N],y[N];
struct man
{
int to,next;
}edg[M];
void init()
{
met(head,-);met(x,);met(edg,);met(y,);cnt=;
}
void add(int u,int v)
{
edg[cnt].to=v;edg[cnt].next=head[u];head[u]=cnt++;
}
bool dfs(int u) {
for(int i=head[u];i!=-;i=edg[i].next) {
int v=edg[i].to;
if(!vis[v]) {
vis[v]=;
if(!y[v]||dfs(y[v])) {
x[u]=v;
y[v]=u;
return true;
}
}
}
return false;
}
void MaxMatch() {
int ans=;
for(int i=; i<n; i++) {
if(!x[i]) {
met(vis,);
if(dfs(i))ans++;
}
}
//printf("ans=%d\n",ans);
printf("%d\n",n-ans/);
}
int main()
{
while(~scanf("%d\n",&n)){
init();
int u,nn,v;
for(int i=;i<n;i++){
scanf("%d: (%d)",&u,&nn);
for(int j=;j<nn;j++){
scanf("%d",&v);
add(i,v);
}
}
MaxMatch();
}
return ;
}

POJ Girls and Boys (最大独立点集)的更多相关文章

  1. hdu 1068 Girls and Boys 最大独立点集 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 思路: 求一集合满足,两两之间没有恋爱关系 思路: 最大独立点集=顶点数-最大匹配数 这里给出的 ...

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

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

  3. POJ 1466 Girls and Boys

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

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

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

  5. poj 1466 Girls and Boys 二分图的最大匹配

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

  6. POJ 1466 Girls and Boys (匈牙利算法 最大独立集)

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 10912   Accepted: 4887 D ...

  7. POJ 1466:Girls and Boys 二分图的最大点独立集

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 11097   Accepted: 4960 D ...

  8. HDU1068 最大独立点集

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

  9. Girls and Boys

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

随机推荐

  1. linux卸载挂载点显示device is busy

    在做umount设备时, device is busy是令人头痛的提示: [root@delphi /]# umount /dev/cdrom umount: /mnt/cdrom: device i ...

  2. 新发布GoldenGate 12c版本中的主要特性

        业界领先的实时数据集成工具GoldenGate现在可以帮助企业在传统数据库和云平台.大数据平台之间进行实时复制.新的OGG 12c支持更多的异构数据库和大数据平台,进一步提升可管理性和对混合云 ...

  3. ODI 12.1.3发布,提升支持大数据的能力

    此次发布的ODI新版本,目的是更好的支持当前市场上的大数据平台. 大数据基因在不改变ODI工作效率的情况下,ODI增加了越来越多的数据源集成能力.ODI是在Oracle平台上标准的E-LT工具,事实上 ...

  4. getSingleResult 和 selectone

    都是返回一个对象,如果找到一个以上的对象会报错,这个在登录验证和添加的时候可能会有点小用,因为登录和添加的时候都要判断是不是数据库有这个username,登录的时候希望有,添加的时候希望没有,但是两者 ...

  5. HTML--11marquee标签

    页面的自动滚动效果,可由javascript来实现, 但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用marquee ...

  6. oracle删除数据库中的所有数据的拼接语句

    create or replace function count_rows/**查询各表实际记录数*/(table_name in varchar2,owner in varchar2 default ...

  7. Ubuntu 14.10 下MySQL无法远程连接问题

    安装好MySQL之后,如果需要远程连接,那么需要做一些配置,否则会出现一些类似的错误,如 mysql root用户ERROR (): mysql 远程登录 ERROR () mysql 远程登录200 ...

  8. 生成Apk遇到的问题

    conversion to dalvik format failed with error 1 android proguard keep Parameterized class

  9. Java中线程的锁和数据库中的事务隔离级别

    当涉及到两个或多个线程操作同一个资源时,就会出现锁的问题. 数据库中的某一条记录或者是某一个对象中的字段,可以修改,也可以读取,一般情况下,读取的那个方法应该加锁(即用synchronized互斥), ...

  10. BZOJ 3999 旅游

    .......好长啊. #include<iostream> #include<cstdio> #include<cstring> #include<algo ...