Girls and Boys(二分图)
来源:互联网 发布:360软件检测 编辑:程序博客网 时间:2024/05/29 09:24
点击打开链接
B - Girls and Boys
Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
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
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N=505;int f[N];bool fr[N][N];bool vis[N];int n,m;bool find(int x){for (int i = 1 ; i <= n ; i++)//这个地方i<=n,是i{if (fr[x][i] && !vis[i]){vis[i] = true;if (f[i] == -1){f[i] = x;return true;}else if (find(f[i])){f[i] = x;return true;}}}return false;}int main(){while (~scanf ("%d %d",&n,&m)){memset(f,-1,sizeof(f));memset(fr,false,sizeof(fr));for (int i = 1 ; i <= m ; i++){int x,y;scanf ("%d %d",&x,&y);fr[x][y] = true;}int ans = 0; for (int i = 1 ; i <= n ; i++){memset(vis,false,sizeof(vis));if (find(i))ans++;}printf ("%d\n",ans);}return 0;}
阅读全文
0 0
- Girls and Boys(二分图)
- POJ 1466 Girls and Boys 二分图
- Girls and Boys(二分图)
- Girls and Boys(二分图匹配)
- 二分图基础--Girls and Boys
- hdu1068 Girls and Boys(二分图)
- 暑假-二分图-E - Girls and Boys
- poj Girls and Boys 二分图匹配
- HDU 1068 Girls and Boys 二分图
- hdoj 1068 Girls and Boys<二分图>
- Hdu1068-Girls and Boys-【二分图】
- Girls and Boys(二分图--匈牙利算法)
- Girls and Boys (二分匹配)
- hdu1068(二分)Girls and Boys
- 【图算法之二分图】HDU 1068---Girls and Boys
- 【图算法之二分图】HDU1068---Girls and Boys
- hdu 1068 Girls and Boys(二分图匹配)
- hdu Girls and Boys(二分图的最大独立集)
- EffectiveC++学习笔记-条款49
- FreeMarker入门笔记一之helloworld
- SQL Server 2008 R2 中英文 开发版/企业版/标准版 下载
- Neo4j
- php网站乱码,完美解决乱码、一键解决PHP的乱码、php网站乱码矫正神器、PHP乱码修复器
- Girls and Boys(二分图)
- Unity7--键盘按键、沿Z轴移动来回循环、PingPong用法
- plist文件
- Java实现快速排序
- java防止脚本注入,通过拦截器实现
- Qt Quick学习笔记(三)
- HDU-2017中国大学生程序设计竞赛-网络选拔赛-部分题解及代码
- ZOJ2105 终于找到错误
- poj 2236 Wireless Network(并查集)