Girls and Boys

Time Limit: 5000ms
Memory Limit: 10000KB

This problem will be judged on PKU. Original ID: 1466
64-bit integer IO format: %lld      Java class name: Main

 
 
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

解题:找出相互没关系的一个人数最大的集合。首先,是点!让点多,我们可以求点小!最小点覆盖!那么我们可以求最大匹配数!无向图的最大匹配数要处以2.。。。就这样了

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int to,next;
};
arc g[];
int head[maxn],from[maxn],tot,n;
bool vis[maxn];
void add(int u,int v){
g[tot].to = v;
g[tot].next = head[u];
head[u] = tot++;
}
bool dfs(int u){
for(int i = head[u]; i != -; i = g[i].next){
if(!vis[g[i].to]){
vis[g[i].to] = true;
if(from[g[i].to] == - || dfs(from[g[i].to])){
from[g[i].to] = u;
return true;
}
} }
return false;
}
int main() {
int i,j,k,u,v,ans;
while(~scanf("%d",&n)){
memset(head,-,sizeof(head));
memset(from,-,sizeof(from));
tot = ;
for(i = ; i < n; i++){
scanf("%d: (%d)",&j,&k);
for(j = ; j < k; j++){
scanf("%d",&v);
add(i,v);
add(v,i);
}
}
for(ans = i = ; i < n; i++){
memset(vis,false,sizeof(vis));
if(dfs(i)) ans++;
}
ans >>= ;
printf("%d\n",n-ans);
}
return ;
}

BNUOJ 1585 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. Latex排版工具的使用(一) 分类: Latex 2014-06-14 22:52 448人阅读 评论(0) 收藏

    使用Latex可以排版出漂亮的论文,尤其适合对含有数学公式论文的排版. 下面编写第一Latex源文件,实现对两个数学公式的排版: 新建文件first.tex: \documentclass{artic ...

  2. 随机L系统分形树 分类: 计算机图形学 2014-06-01 23:27 376人阅读 评论(0) 收藏

    下面代码需要插入到MFC项目中运行,实现了计算机图形学中的L系统分形树. class Node { public: int x,y; double direction; Node(){} }; CSt ...

  3. 加密解密(3)Bob到CA申请证书过程

    网络安全中最知名的人物大概就是Bob和Alice了,因为很多安全原理阐述中都用这两个虚拟人物来进行实例说明. 我们来看看Bob是怎么从CA中心获得一个数字证书的: 1.Bob首先创建他自己的密钥对(k ...

  4. java getDocumentBase() 得到的文件夹路径

    参考一个百度知道上的回答 举例说来,假设你的项目文件是xx,而这个xx文件夹是在D盘下的yy文件夹里,即项目文件的完整路径D:\yy\xx,则编译运行文件后,在xx文件夹里会产生名为build的文件夹 ...

  5. Suricata是什么?

    不多说,直接上干货! 见Suricata的官网 https://suricata.readthedocs.io/en/latest/what-is-suricata.html snort.suirca ...

  6. 前台js获得json数据

    $.ajax({ type:"post", url:"testAction.action", data:{ classId:classId }, success ...

  7. 原创 SqlParameter 事务 批量数据插入

    不错,很好,以后防注入批量事务提交虽然麻烦点研究了几个小时,但不会是问题了 SqlCommand cmd; HelpSqlServer helps = new HelpSqlServer(); //定 ...

  8. js 验证码倒计时效果

    function settime(obj) { if(second == 0){ obj.removeAttribute("disabled"); obj.value=" ...

  9. Visual Studio 2013 错误系统找不到指定文件,0x80070002

    错误:Visual Studio 2013 按照成功后,可以创建空web项目,但不能建webform 和 mvc 项目. 提示系统找不到指定文件,0x80070002. 解决方式: Step1: Wi ...

  10. vue2.0 动态切换组件

    组件标签是Vue框架自定义的标签,它的用途就是可以动态绑定我们的组件,根据数据的不同更换不同的组件. <!DOCTYPE html> <html lang="en" ...