链接:http://acm.hdu.edu.cn/showproblem.php?pid=5971

Wrestling Match

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1100    Accepted Submission(s): 420

Problem Description
Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is "good player”, the rest is "bad player”. Now, Xiao Ming is referee of the wrestling match and he has a list of the matches in his hand. At the same time, he knows some people are good players,some are bad players. He believes that every game is a battle between the good and the bad player. Now he wants to know whether all the people can be divided into "good player" and "bad player".
Input
Input contains multiple sets of data.For each set of data,there are four numbers in the first line:N (1 ≤ N≤ 1000)、M(1 ≤M ≤ 10000)、X,Y(X+Y≤N ),in order to show the number of players(numbered 1toN ),the number of matches,the number of known "good players" and the number of known "bad players".In the next M lines,Each line has two numbersa, b(a≠b) ,said there is a game between a and b .The next line has X different numbers.Each number is known as a "good player" number.The last line contains Y different numbers.Each number represents a known "bad player" number.Data guarantees there will not be a player number is a good player and also a bad player.
Output
If all the people can be divided into "good players" and "bad players”, output "YES", otherwise output "NO".
Sample Input
  
5 4 0 0 1 3 1 4 3 5 4 5 5 4 1 0 1 3 1 4 3 5 4 5 2
Sample Output
  
NO YES

题意:给出n个人,m场比赛,x个人为good player,y个人为bad player,每场比赛两个人分分别为good和bad,问good和bad是否会冲突

思路:染色法判二分,先根据已知的人判断,再遍历一遍n个点找到还未判断的,wa了n次,忘记vector初始化的,,,整个人都不好了

代码:

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<functional>
#include<map>
using namespace std;
const int INF = (int)1e9;
const int maxn = 25000 + 10;
typedef long long LL;//视情况定类型  int n, m, x, y;
vector<int>G[maxn];
int color[maxn];void init() {memset(color, 0, sizeof(color));for (int i = 0; i < maxn; i++)G[i].clear();
}int dfs(int s) {for (int i = 0; i < G[s].size(); i++) {int v = G[s][i];if (color[v] == 0) {color[v] = -color[s];if (!dfs(v))return 0;}else if (color[s] == color[v])return 0;}return 1;
}int main() {while (scanf("%d %d %d %d", &n, &m, &x, &y) != EOF) {init();int a, b;for (int i = 0; i < m; i++) {scanf("%d %d", &a, &b);G[a].push_back(b);G[b].push_back(a);}for (int i = 0; i < x; i++) {scanf("%d", &a);color[a] = 1;}for (int i = 0; i < y; i++) {scanf("%d", &b);color[b] = -1;}if ((x == 0 && y == 0) || n==1) {printf("NO\n");continue;}int ans = 1;for (int i = 1; i <= n; i++) {if (color[i]!=0 && dfs(i) == 0) {ans = 0;break;}}for (int i = 1; i <= n; i++) {if (color[i] == 0) {color[i] = 1;if (dfs(i) == 0) {ans = 0;break;}}}if (ans == 1)printf("YES\n");else printf("NO\n");}system("pause");return 0;
}

hdu5971 Wrestling Match(染色法判二分) 2016ACM/ICPC亚洲区大连站相关推荐

  1. 2016ACM/ICPC亚洲区大连站现场赛题解报告(转)

    http://blog.csdn.net/queuelovestack/article/details/53055418 下午重现了一下大连赛区的比赛,感觉有点神奇,重现时居然改了现场赛的数据范围,原 ...

  2. 2016ACM/ICPC亚洲区大连站-补题

    2016ACM/ICPC亚洲区大连站-补题 5971-Wrestling Match 题目隐藏条件:除去已经知道的好人和坏人,如果剩余的人恰好被分成两组,即便不知道这两组哪组是好人,也是输出YES 做 ...

  3. 2016ACM/ICPC亚洲区大连站现场赛题解报告

    此文章可以使用目录功能哟↑(点击上方[+]) 下午重现了一下大连赛区的比赛,感觉有点神奇,重现时居然改了现场赛的数据范围,原本过的人数比较多的题结果重现过的变少了,而原本现场赛全场过的人最少的题重现做 ...

  4. 2016ACM/ICPC亚洲区大连站题解

    以下所有AC题解程序来自"仙客传奇"团队. AC题数:10/11 ABCDFHIJK A. Wrestling Match AC的C++语言程序: #include <ios ...

  5. 【2016ACM/ICPC亚洲区大连站C】HDU - 5973 Game of Taking Stones 威佐夫博弈

    题意 给你两个石堆的石头数量,两个人轮流拿,两人轮流从任意一堆取至少一个或者从两堆取同样多的物品.问你先手获胜还是后手胜. http://acm.hdu.edu.cn/showproblem.php? ...

  6. 2016ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)

    目录 A Thickest Burger B Relative atomic mass C Recursive sequence · 矩阵快速幂 E Counting Cliques · 暴力 H G ...

  7. HDU 5952 Counting Cliques(2016ACM/ICPC亚洲区沈阳站-重现赛)

    题目分析 这道题看样子没有什么办法,主要就是有策略的暴力,因为每个点连接的点不超过20个,那么就可以直接进行暴力,但是这样会有很多重复,因此需要剪枝,具体情况就是每次搜过一个点之后就把这个点连接的所有 ...

  8. POJ 2942 Knights of the Round Table 【点双联通 + 二分图染色法判奇环】

    传送门 亚瑟王要在圆桌上召开骑士会议,为了不引发骑士之间的冲突,并且能够让会议的议题有令人满意的结果,每次开会前都必须对出席会议的骑士有如下要求: 1. 相互憎恨的两个骑士不能坐在直接相邻的2个位置: ...

  9. poj2942 圆桌骑士(点双连通分量+二分图染色法判奇环)

    题意:一些骑士,他们有些人之间有矛盾,现在要求选出一些骑士围成一圈,圈要满足如下条件:1.人数大于1.2.总人数为奇数.3.有仇恨的骑士不能挨着坐.问有几个骑士不能和任何人形成任何的圆圈. 分析:图论 ...

  10. HDU Problem - 5971 Wrestling Match(染色)

    题目链接 Problem Description Nowadays, at least one wrestling match is held every year in our country. T ...

最新文章

  1. 死磕Synchronized底层实现
  2. oracle php 执行时间,在执行Oracle pl/sql-oci8的PHP中,什么时候执行自动回滚?
  3. org.hibernate.HibernateException: connnection proxy not usable after transaction
  4. win10 安装vc++6.0(亲测可用)
  5. poj - 2356 Find a multiple
  6. 存储过程,触发器,事务和锁
  7. Python IDLE入门
  8. 循序渐进看Java web日志跟踪(2)-Java日志API认识
  9. 技术分享 | jaeger链路日志实现
  10. 【ArcGIS遇上Python】长时间序列(30年)每两组栅格数据对应做减法运算求物候参数
  11. 欧拉函数的性质及其证明
  12. 动手学深度学习(PyTorch实现)(九)--VGGNet模型
  13. python操作pdf加密解密
  14. Python Web 框架-Django day07
  15. 基于元数据规则的大数据解决方案
  16. 【bioinfo】bbtools:bbmerge 二代测序reads合并工具了解
  17. PS把图片切成九宫格
  18. 百度输入法键盘android,百度输入法Android 1.2.0正式版 支持智能手写
  19. openwrt编译固件流程
  20. atmega32u4与linux,实用:Atmega 32U4 控制电路 持续更新中

热门文章

  1. 静息态fMRI方法在脑动力学表征上的比较
  2. Vim(Neovim)配置coc.nvim
  3. 我是否该走编程这条路?
  4. Android蓝牙开发浅谈 __ 耳机录音
  5. 您是哪种Java开发人员? 参加我们的Java测验找出答案!
  6. 翔楼新材通过注册:年营收10.6亿 清研汽车是股东
  7. 自媒体视频如何原创?自媒体原视频制作流程,5步就够了
  8. 2023-2024年最值得选的Java毕业设计选题大全:500个热门选题推荐✅
  9. 猫头虎博主赠书一期:《Kubernetes原生微服务开发》
  10. 和平精英体验服开测:丧尸模式终于上线,你会选择回归吗?