HDU 5971 Wrestling Match(染色+暴力)
来源:互联网 发布:av淘宝2017在线 编辑:程序博客网 时间:2024/05/21 10:09
题目分析
主要的策略就是如果有已经确定的点,那么很明显沿着这条边直接跑就可以了,判断其相连的所有点时good player 还是 bad player,如果所有已经明确了的所有已经明确了的点都没有相邻边,那么直接找一个没有被标记过的点跑一下就可以了。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1005;struct Edge{ int to, next;}e[maxn*20];int head[maxn], color[maxn], tot;void addedge(int from, int to){ e[tot].to = to; e[tot].next = head[from]; head[from] = tot++;}bool dfs(int u, int fa){ for(int i = head[u]; i != -1; i = e[i].next){ int v = e[i].to; if(v == fa) continue; if(color[v] == color[u]) return false; if(!color[v]){ color[v] = 3 - color[u]; if(!dfs(v, u)) return false; } } return true;}void init(){ tot = 0; memset(head, -1, sizeof(head)); memset(color, 0, sizeof(color));}int main(){ int n, m, x, y; while(scanf("%d%d%d%d", &n, &m, &x, &y) != EOF){ init(); int from, to; for(int i = 0; i < m; i++){ scanf("%d%d", &from, &to); addedge(from, to); addedge(to, from); } int xx; int flag = true, cnt = 1; for(int i = 0; i < x; i++){ scanf("%d", &xx); if(!color[xx]){ color[xx] = 1; if(head[xx] != -1) cnt = 0; flag = flag&&dfs(xx, -1); } else if(color[xx] == 2) flag = false; } for(int i = 0; i < y; i++){ scanf("%d", &xx); if(!color[xx]){ color[xx] = 2; if(head[xx] != -1) cnt = 0; flag = flag&&dfs(xx, -1); } else if(color[xx] == 1) flag = false; } if(!flag){ printf("NO\n"); continue; } else{ if(cnt){ for(int i = 1; i <= n; i++) if(!color[i]){ color[i] = 1; flag = flag&&dfs(i, -1); break; } for(int i = 1; i <= n; i++) if(!color[i]){ flag = false; break; } } else{ for(int i = 1; i <= n; i++) if(!color[i]){ flag = false; break;} } } if(flag) printf("YES\n"); else printf("NO\n"); } return 0;}
1 0
- HDU 5971 Wrestling Match(染色+暴力)
- -----染色问题 hdu 5971-Wrestling Match
- 【HDU】5971-Wrestling Match 二分染色
- HDU 5971 Wrestling Match(二分图染色)
- hdu 5971 Wrestling Match
- HDU 5971 Wrestling Match
- hdu 5971 Wrestling Match
- hdu 5971Wrestling Match
- HDU 5971 Wrestling Match(深搜)
- HDU 5971 Wrestling Match(染色法二分图 OR 并查集)
- HDOJ 5971 Wrestling Match【2016大连现场】【dfs二分染色】
- hdu 5971 Wrestling Match(队列)
- HDU 5971 icpc 大连 A Wrestling Match
- HDU 5971 Wrestling Match(dfs)
- HDU5971 Wrestling Match(二分图染色)
- Wrestling Match【DFS+二分图染色】
- hdoj 5971 Wrestling Match
- 【HDU 5971 Wrestling Match】+ 2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学) + 二分图染色
- Java学习3:基于Intellij IDEA实现一个简单Servlet
- 在java中如何将一个长整形的数变为数组类型
- 界面设计(K)
- Java 变量类型
- 字符串编程
- HDU 5971 Wrestling Match(染色+暴力)
- 《剑指》6
- javascript基础笔记(十六)之js实现99乘法表
- MyEclipse中运行Struts2框架出错
- Parallels Desktop12 双11钜惠 ¥298
- MySQL集群
- react-naive 搭建开发环境(Windows)
- 设计模式的六大原则
- 多个user.name同时使用git