POJ1446 Girls and Boys
来源:互联网 发布:大数据框架hadoop 编辑:程序博客网 时间:2024/06/03 19:38
Girls and Boys
Time Limit: 5000MS Memory Limit: 10000KTotal 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.
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
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
——————————————————————————————————
题目的意思是给出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 longconst 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;}
阅读全文
0 0
- POJ1446 Girls and Boys
- Girls and Boys
- hdu1068 Girls and Boys
- Girls and Boys
- zoj1137:Girls and Boys
- poj1466 - Girls and Boys
- hdu1608 Girls and Boys
- A. Boys and Girls
- HDU1068--Girls and Boys
- HDU1068:Girls and Boys
- HDU1068-Girls and Boys
- poj1466--Girls and Boys
- POJ1466 Girls and Boys
- Girls and Boys
- Girls and Boys
- Girls and Boys
- poj1466 Girls and Boys
- Girls and Boys
- Vim编辑nginx配置文件时高亮显示
- 安卓WebView问题总汇(持续更新)
- PHP实现选择排序算法
- ebpf 实例
- @RequestParam,@PathParam,@PathVariable等注解区别
- POJ1446 Girls and Boys
- 欢迎使用CSDN-markdown编辑器
- 坑爹的logstash条件判断
- 中小企业迎品牌建设最佳契机 中企动力赋能数字化智能经营
- 正则表达式手机号(大陆,香港)
- Java 内部类知识点
- 什么是热修复技术
- 导弹拦截系统(附详细讲解,误喷)
- POJ 1286 A