Girls and Boys
Time Limit: 5000MS   Memory Limit: 10000K
Total Submissions: 12747   Accepted: 5678

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

Source

——————————————————————————————————

题目的意思是给出n个学生喜欢的关系,问最多选出多少个人没有喜欢关系

思路:求最大独立集,最大独立集=点数n-最大匹配数

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f; const int MAXN=1000;
int uN,vN; //u,v数目
int g[MAXN][MAXN];//编号是0~n-1的
int linker[MAXN];
bool used[MAXN];
int mat[MAXN];
int aa[MAXN];
struct area
{
int x1,x2,y1,y2;
} s[100005];
struct point
{
int x,y;
} p[100005]; bool dfs(int u)
{
int v;
for(v=0; v<vN; v++)
if(g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
}
int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=0; u<uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int n,m,x,y;
int cas=1;
while(~scanf("%d",&n))
{
memset(g,0,sizeof g);
for(int i=0; i<n; i++)
{
scanf("%d: (%d)",&x,&m);
for(int i=0; i<m; i++)
{
scanf("%d",&y);
g[x][y]=1;
}
}
uN=vN=n;
printf("%d\n",n-hungary()/2);
}
return 0;
}

  

POJ1446 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. Girls and Boys

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

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

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

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

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

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

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

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

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

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

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

  8. Girls and Boys(匈牙利)

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

  9. (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 ...

随机推荐

  1. PAT 1033 旧键盘打字(20)(20 分)

    1033 旧键盘打字(20)(20 分) 旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在2 ...

  2. Minimum number of steps 805D

    http://codeforces.com/contest/805/problem/D D. Minimum number of steps time limit per test 1 second ...

  3. IOS 将图片转换为圆角图

    UIImage+wiRoundedRectImage.h #import <UIKit/UIKit.h> @interface UIImage (wiRoundedRectImage) + ...

  4. git的命令详解

    # git三个区 + 工作区: 写代码的地方 + 暂存区: 暂时存储代码 + 仓库区: 代码提交到了仓库区,就生成一条历史记录(版本) 工作区===> 暂存区 ===> 仓库区 # git ...

  5. js,jquery的数字型字符串变量比较大小

    转:http://blog.csdn.net/dxnn520/article/details/8267173 var定义的变量应该是字符串,有时没有经过类型转换而进行比较的话,小于十的话还可以,如果大 ...

  6. ssrf绕过总结

    前言 昨天忘了在公众号还是微博上看到的了,看到一个SSRF绕过的技巧,使用的是 ⓔⓧⓐⓜⓟⓛⓔ.ⓒⓞⓜ 绕过的,自己也没遇到过.然后想想自己对SSRF绕过还是停留在之前的了解,也没学习过新的绕过方法, ...

  7. Linux学习笔记:JDK安装

    系统为CentOS 7,安装Oracle jdk1.8 卸载系统自带的Openjdk(若无可跳过这一步,可以通过 java -version 查看),步骤是:查找Openjdk,卸载Openjdk r ...

  8. [网络]10M、100M、1000M网线的水晶头接法

    在网络维护过程中经常要自己制作网线,水晶头理论上是这样接的: 10M和100M和1000M以太网在使用网线时,对网线各自有不同的要求. 10M和100M在目前来说,连接网络的时候,只用到两对线来传输网 ...

  9. linux_修改ip(重启后永久生效)

    vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet UUID=a20869f2-4095-4e5d-9b0c- ...

  10. Vue.directive基础,在Vue模块开发中使用

    这是从网上找到的一个案例,由于网上的案例有坑,所以我在这里从新上传一次! 首先在main.js里引入两个自定义指令 import {focus, drag} from './components/da ...