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".

InputInput 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.OutputIf all the people can be divided into "good players" and "bad players”, output "YES", otherwise output "NO".Sample Input

  1. 5 4 0 0
  2. 1 3
  3. 1 4
  4. 3 5
  5. 4 5
  6. 5 4 1 0
  7. 1 3
  8. 1 4
  9. 3 5
  10. 4 5
  11. 2

Sample Output

  1. NO
  2. YES

Hint

  1. /*
  2. * @Author: lyuc
  3. * @Date: 2017-05-01 15:48:50
  4. * @Last Modified by: lyuc
  5. * @Last Modified time: 2017-05-01 20:33:47
  6. */
  7. /**
  8. * 题意:有n个人每个人只能是好人或者是坏人,给你n对人的关系,每对的中两个人的关系是对立的,一定有一个
  9. * 是坏人一个是好人,并且给了 x个确定是好人的编号, y个确定是坏人的编号,现在让你判断,是否能将
  10. * 所有人划分成两个阵营(有人的身份不能确定也不行)
  11. *
  12. * 思路:裸的二分染色,按照输入情况进行建边,然后按照输入的x,y进行染色判断如果有矛盾那一定是不行的,
  13. * 最后在讲给出的条件进行染色,最后如果有身份不明的人就可以除去了
  14. */
  15. #include <stdio.h>
  16. #include <vector>
  17. #include <string.h>
  18. #include <queue>
  19. #include <iostream>
  20. using namespace std;
  21. int n,m;
  22. int x,y;
  23. int a[],b[];
  24. vector<int>edge[];
  25. int vis[];
  26. bool ok;
  27. int str;
  28. void bfs(int u,int flag){
  29. queue<int>q;
  30. q.push(u);
  31. vis[u]=flag;
  32. while(!q.empty()){
  33. int tmp=q.front();
  34. q.pop();
  35. for(int i=;i<edge[tmp].size();i++){
  36. int v=edge[tmp][i];
  37. if(vis[v]==vis[tmp]){
  38. ok=false;
  39. return;
  40. }
  41. if(vis[v]==){
  42. vis[v]=(-vis[tmp]);
  43. q.push(v);
  44. }
  45. }
  46. }
  47. }
  48. void init(){
  49. ok=true;
  50. memset(vis,,sizeof vis);
  51. for(int i=;i<;i++){
  52. edge[i].clear();
  53. }
  54. }
  55. int main(){
  56. // freopen("in.txt","r",stdin);
  57. while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF){
  58. init();
  59. for(int i=;i<m;i++){
  60. scanf("%d%d",&a[i],&b[i]);
  61. edge[a[i]].push_back(b[i]);
  62. edge[b[i]].push_back(a[i]);
  63. }
  64. for(int i=;i<x;i++){
  65. scanf("%d",&str);
  66. if(vis[str]==-){
  67. ok=false;
  68. }
  69. bfs(str,);
  70. }
  71. for(int i=;i<y;i++){
  72. scanf("%d",&str);
  73. if(vis[str]==){
  74. ok=false;
  75. }
  76. bfs(str,-);
  77. }
  78. for(int i=;i<m;i++){
  79. if(vis[a[i]]==&&vis[b[i]]==)
  80. bfs(a[i],);
  81. }
  82. for(int i=;i<=n;i++){
  83. if(vis[i]==){
  84. ok=false;
  85. break;
  86. }
  87. }
  88. printf(ok?"YES\n":"NO\n");
  89. }
  90. return ;
  91. }

A - Wrestling Match HDU - 5971的更多相关文章

  1. hdu 5971 Wrestling Match

    题目链接: hdu 5971 Wrestling Match 题意:N个选手,M场比赛,已知x个好人,y个坏人,问能否将选手划分成好人和坏人两个阵营,保证每场比赛必有一个好人和一个坏人参加. 题解:d ...

  2. hdu 5971 Wrestling Match 判断能否构成二分图

    http://acm.hdu.edu.cn/showproblem.php?pid=5971 Wrestling Match Time Limit: 2000/1000 MS (Java/Others ...

  3. HDU 5971 二分图判定

    Wrestling Match Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. HDU 5971 Wrestling Match (二分图)

    题意:给定n个人的两两比赛,每个人要么是good 要么是bad,现在问你能不能唯一确定并且是合理的. 析:其实就是一个二分图染色,如果产生矛盾了就是不能,否则就是可以的. 代码如下: #pragma ...

  5. hdu 5971 Wrestling Match 二分图染色

    题目链接 题意 \(n\)人进行\(m\)场比赛,给定\(m\)场比赛的双方编号:再给定已知的为\(good\ player\)的\(x\)个人的编号,已知的为\(bad\ player\)的\(y\ ...

  6. HDU 5971"Wrestling Match"(二分图染色)

    传送门 •题意 给出 n 个人,m 场比赛: 这 m 场比赛,每一场比赛中的对决的两人,一个属于 "good player" 另一个属于 "bad player" ...

  7. 【HDOJ5971】Wrestling Match(二分图,并查集)

    题意:有n个人,m场比赛,x个人为good player,y个人为bad player, 每场比赛两个人分分别为good和bad,问good和bad是否会冲突 1 ≤ N≤ 1000,1 ≤M ≤ 1 ...

  8. HDU 6095 17多校5 Rikka with Competition(思维简单题)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  9. hdoj 5971

    Wrestling Match Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

随机推荐

  1. windows 下面安装gcc

    0.环境说明: win7 家庭版64位 1.下载编译器 https://sourceforge.net/projects/mingw/?source=typ_redirect 如图所示: 注意,安装的 ...

  2. KMP算法的来龙去脉

    1. 引言 字符串匹配是极为常见的一种模式匹配.简单地说,就是判断主串TT中是否出现该模式串PP,即PP为TT的子串.特别地,定义主串为T[0-n−1]T[0-n−1],模式串为P[0-p−1]P[0 ...

  3. eclipse导入源码

    1.window-----preferences 2.java---installed jres(点击不用展开)---选中使用的jar包-----editor 3.选中rt.jar ------sou ...

  4. ARKit 增强现实平台 尝试(Xcode9 iOS11 A9处理器)

    一, Xcode 将加​​载其主页面并显示模板选择页面.模板简化了入门过程.然后选择增强现实应用程序图标,单击"下一步"按钮. 二, 运行程序会看到一个飞机 三,尝试更换模型 在这 ...

  5. vue实例讲解之vuex的使用

    vuex是一个状态管理插件,本文通过一个简单的实例来讲解一下,vuex的使用. 先看一张官方的图: 这个图新手一看估计是蒙的,简单解释一下,这个图表示的就是vue通过Action Mutations ...

  6. Java的基本程序设计结构【2】

    注释 与大多数程序设计语言一样,Java 中的注释也不会出现在可执行程序中.因此,可以在源程序中根据需要添加任意多的注释,而不必担心可执行代码会膨胀.在Java 中,有三种书写注释的方式. 最常用的方 ...

  7. 分享基于分布式Http长连接框架--设计模型

    追求简单的设计. 也许你的设计功能很强大,但能够在满足你需求的前提下尽量简单明了设计. 当你的设计过于复杂的时候想想是不是有其它路可以走,你站在别人的角度想下,如果别人看了你的设计会不会心领神会,还是 ...

  8. windows下怎么解决Python双版本问题

    相信大家会在windows下会遇到Python双版本问题 当我们装了Python2和Python3时我们好只能在命令栏调出最高版本的那个低版本的难道消失了吗?今天我们就解决这个问题! 1.下载 我们在 ...

  9. 57、Bootstrap中文文档

    给大家介绍一个前端框架让你从此写起前端代码与之先前相比如有神助般的效果拉就是Bootstrap. 一.Bootstrap的下载 Bootstrap,由Twitter的设计师Mark Otto和Jaco ...

  10. Java面向对象 网络编程 上

     Java面向对象 网络编程 上 知识概要:                     (1)网络模型 (2)网络通讯要素 (3)UDP TCP 概念 (4)Socket (5)UDP TCP 传输 ...