【二分图|最大点独立集】POJ-1466 Girls and Boys
来源:互联网 发布:python爬虫能做什么 编辑:程序博客网 时间:2024/06/05 09:22
Girls and Boys
Time Limit: 5000MS Memory Limit: 10000K
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
————————————————————簡単な分割線————————————————————
思路:最大点独立集 = 顶点数 - 匹配数
代码如下:
/*ID: j.sure.1PROG:LANG: C++*//****************************************/#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <ctime>#include <cmath>#include <stack>#include <queue>#include <vector>#include <map>#include <string>#include <climits>#include <iostream>#define LL long longusing namespace std;const int INF = 0x3f3f3f3f;/****************************************/const int N = 555, M = 66666;int n, tot, head[N], cou[N];bool vis[N];struct Edge {int v, next;Edge(){}Edge(int _v, int _next):v(_v), next(_next){}}edge[M];void init(){tot = 0;memset(head, -1, sizeof(head));}void add(int u, int v){edge[tot] = Edge(v, head[u]);head[u] = tot++;}int dfs(int u){for(int i = head[u]; ~i; i = edge[i].next) {int v = edge[i].v;if(!vis[v]) {vis[v] = true;if(cou[v] == -1 || dfs(cou[v])) {cou[v] = u;return 1;}}}return 0;}int match(){int ret = 0;memset(cou, -1, sizeof(cou));for(int i = 0; i < n; i++) {memset(vis, 0, sizeof(vis));ret += dfs(i);}return ret / 2;}int main(){#ifdef J_Sure//freopen("000.in", "r", stdin);//freopen(".out", "w", stdout);#endifwhile(~scanf("%d", &n)) {init();int u, x, v;for(int i = 0; i < n; i++) {//0: (3) 4 5 6scanf("%d: (%d)", &u, &x);for(int k = 0; k < x; k++) {scanf("%d", &v);add(u, v);}}int ans = match();printf("%d\n", n - ans);}return 0;}
0 0
- POJ-1466-Girls and Boys(二分图最大独立集)
- POJ 1466 Girls and Boys(二分图最大独立集)
- POJ 1466 Girls and Boys(二分图最大独立集)
- POJ 1466 Girls and Boys(二分图最大独立集)
- POJ 1466 Girls and Boys(二分图最大独立集)
- POJ 1466 Girls and Boys(二分图匹配+拆点+最大独立集)
- 【二分图|最大点独立集】POJ-1466 Girls and Boys
- POJ 1466:Girls and Boys 二分图的最大点独立集
- POJ 1466 && ZOJ 1137--Girls and Boys【二分图 && 最大点独立集】
- POJ 1466 Girls and Boys(最大独立点集)
- POJ 1466 Girls and Boys (最大独立点集)
- POJ 1466 Girls and Boys(最大独立点集)
- poj 1466 Girls and Boys (二分图最大独立集)
- POJ 1466 Girls and Boys 最大独立集 二分图匹配
- POJ - 1466 Girls and Boys 二分图+最大独立集
- poj 1466 Girls and Boys (最大独立)
- hdu Girls and Boys(二分图的最大独立集)
- ZOJ 1137 Girls and Boys(二分图最大独立集)
- android项目 之 记事本(15) ----- 保存手写及绘图
- 为我签订去外地去的
- JNI常用函数
- R3修改线程上下文EIP实现的无模块注入
- querySelectorAll 方法相比 getElementsBy 系列方法有什么区别
- 【二分图|最大点独立集】POJ-1466 Girls and Boys
- POJ 3762 The Bonus Salary!(最小K覆盖)
- 如何Samba建立共享
- ASIHTTPRequest第三方网络请求详解
- java-反射
- RabbitMQ学习之spring整合发送同步消息
- java定时任务
- Oracle 删除表中记录 如何释放表及表空间大小
- 如何设计一个基于Node.js和Express的网站架构?