【hdu 1068 基础二分图】Girls and Boys
来源:互联网 发布:小学生裙子淘宝 编辑:程序博客网 时间:2024/05/14 19:42
Girls and Boys
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11527 Accepted Submission(s): 5412
Total Submission(s): 11527 Accepted Submission(s): 5412
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.
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
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
ac代码
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <vector>#include <string>#include <sstream>#include <map>#include <set>#include <queue>#include <stack>#include <list>#include <bitset>#include <functional>#include <utility>//pair#include <iomanip>using namespace std;#define MAX 1005int n,m;int match[MAX];bool visit[MAX],p[MAX][MAX];//模板开始bool dfs(int k){ int i,t; for(i=0; i<m; i++) { if(p[k][i] && !visit[i]) { visit[i] = true; t = match[i]; match[i] = k; if(t == -1 || dfs(t)) return true; match[i] = t; } } return false;} int Max_match(){ int ans = 0; memset(match,-1,sizeof(match)); for(int i=0; i<n; i++) { memset(visit,0,sizeof(visit)); if(dfs(i)) ans++; } return ans;} //模板结束int main(){ int t,i,a,b,c; while(scanf("%d",&t)!=EOF) { n = t; m = t; memset(p,0,sizeof(p)); while(t--) { scanf("%d: (%d)",&a,&b); for(i=0;i<b;i++) { scanf("%d",&c); p[a][c] = 1; } } printf("%d\n",n - Max_match()/2); } return 0;}
1 0
- 【hdu 1068 基础二分图】Girls and Boys
- HDU 1068 Girls and Boys 二分图
- hdu 1068 Girls and Boys 二分匹配
- hdu 1068 Girls and Boys (二分匹配)
- 二分图基础--Girls and Boys
- 【图算法之二分图】HDU 1068---Girls and Boys
- hdu 1068 Girls and Boys(二分图匹配)
- hdu 1068 Girls and Boys (二分图匹配)
- HDU 1068Girls and Boys(二分图最大匹配)
- HDU 1068 Girls And Boys 二分图题解
- hdu 1068 Girls and Boys(水题,二分图匹配)
- HDU 1068 Girls and Boys 【二分图+增广路】
- HDU 1068 Girls and Boys(二分图最大匹配)
- hdu 1068 Girls and Boys 二分图的最大匹配
- 【HDU 1068】Girls and Boys(二分图)
- hdoj 1068 Girls and Boys<二分图>
- Girls and Boys(二分图)
- hdu 1068 Girls and Boys(最大独立集,二分匹配)
- 根据实例详解Java中的反射机制
- 车上诊断插头的定义
- 复习笔记-java基础知识
- Codeforces 798D Mike and distribution【思维+贪心】好题!好题!感觉智商受到了一万点伤害= =
- 10.SElinux
- 【hdu 1068 基础二分图】Girls and Boys
- spark-streaming-[6]-KafkaWordCount和KafkaWordCountProducer(Receiver-based Approach)
- Spring框架基础知识
- 设计模式之迭代器模式
- Windows 虚拟地址转译(PAE)
- 《现代操作系统(中文第三版)》课后习题——第四章 文件系统
- IDEA git 使用 将当前工程添加为git仓库 add root
- const关键字详细解析
- BFS预处理——UVAlive 7263