【二分图】专题
来源:互联网 发布:聚类算法哪几种 编辑:程序博客网 时间:2024/06/15 21:55
refer:http://blog.csdn.net/hackbuteer1/article/details/7398008
http://poj.org/problem?id=1469
#include <iostream>#include <math.h>#include <algorithm>#include <string.h>#include <stdio.h>using namespace std;bool g[110][310];bool visit[310];int match[310];int p, n;bool dfs(int u){ for(int i = 1; i <= n; i++){ if(g[u][i] && !visit[i]){ visit[i] = true; if(match[i] == -1 || dfs(match[i])){ match[i] = u; return true; } } } return false;}int main(){ int t; scanf("%d", &t); while(t--) { scanf("%d%d", &p, &n); for(int i = 1; i <= p; i++){ for(int j = 1; j <= n; j++){ g[i][j] = false; } } for(int i = 1; i <= n; i++) match[i] = -1; bool flag = false; for(int i = 1; i <= p; i++) //input { int times; scanf("%d", ×); if(times == 0) flag = true; while(times--){ int a; scanf("%d", &a); g[i][a] = true; } } if(!flag){ int ans = 0; for(int i = 1; i <= p; i++){ memset(visit, false, sizeof(visit)); if(dfs(i)) ans++; } if(ans == p) puts("YES"); else puts("NO"); } else puts("NO"); } return 0;}
http://acm.hdu.edu.cn/showproblem.php?pid=2444
#include <iostream>#include <math.h>#include <algorithm>#include <string.h>#include <stdio.h>using namespace std;#define white 1#define black 0#define none -1int n;bool g[220][220];int color[220];bool visite[220];bool DFS(int u){ for(int i = 0; i <= n; i++) { if(g[u][i]) { if(color[i] == none) { color[i] = 1 - color[u]; if(DFS(i) == true) return true; } else if(color[u] == color[i]) return true; } } return false;}bool isbigr(){ memset(color, -1, sizeof(color)); color[1] = white; //printf("%d %d", color[1], color[3]); if(DFS(1)) return true; return false;}bool match(int u){ for(int i = 1; i <= n; i++) { if(g[u][i] && !visite[i]) { visite[i] = true; if(color[i] == -1 || match(color[i])) { color[i] = u; return true; } } } return false;}int main(){ int m; while(scanf("%d %d", &n, &m) != -1) { for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) g[i][j] = false; while(m--) { int a, b; scanf("%d %d", &a, &b); g[a][b] = true; } if(isbigr()) puts("No"); else { for(int i = 0; i <= n; i++) color[i] = -1; int ans = 0; for(int i = 1; i<= n; i++) { memset(visite, false, sizeof(visite)); if(match(i)) ans++; } printf("%d\n", ans); } }}
0 0
- 【二分图】专题
- 二分图专题
- 专题:二分图匹配
- 图论专题 二分图
- 图论专题 二分图
- 二分图最大匹配专题
- 【二分图匹配入门专题1】A
- 【二分图匹配入门专题1】B
- 【二分图匹配入门专题1】C
- 【二分图匹配入门专题1】D
- 【二分图匹配入门专题1】F
- 【二分图匹配入门专题1】E
- 【二分图匹配入门专题1】H
- 【二分图匹配入门专题1】I
- 【二分图匹配入门专题1】K
- 【二分图匹配入门专题1】L
- 【二分图匹配入门专题1】M
- 【二分图匹配入门专题1】 N
- 3年前 --- 记自己成为程序员的旅程
- 第九周项目6(2)
- Unable to execute dex: Multiple dex files define
- UVA 10635
- 软工实验第六周任务
- 【二分图】专题
- 【智能家居篇】wifi网络接入原理(中)——认证Authentication
- BZOJ 2301: [HAOI2011]Problem b
- 文件的基本操作
- Java面向对象基础二
- 【bzoj 2173】: 整数的lqp拆分
- linux系统安装增强功能与集群网络配置
- VS2010创建并使用DLL
- 工作周记