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

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

Hint

/*
* @Author: lyuc
* @Date: 2017-05-01 15:48:50
* @Last Modified by: lyuc
* @Last Modified time: 2017-05-01 20:33:47
*/
/**
* 题意:有n个人每个人只能是好人或者是坏人,给你n对人的关系,每对的中两个人的关系是对立的,一定有一个
* 是坏人一个是好人,并且给了 x个确定是好人的编号, y个确定是坏人的编号,现在让你判断,是否能将
* 所有人划分成两个阵营(有人的身份不能确定也不行)
*
* 思路:裸的二分染色,按照输入情况进行建边,然后按照输入的x,y进行染色判断如果有矛盾那一定是不行的,
* 最后在讲给出的条件进行染色,最后如果有身份不明的人就可以除去了
*/
#include <stdio.h>
#include <vector>
#include <string.h>
#include <queue>
#include <iostream>
using namespace std;
int n,m;
int x,y;
int a[],b[];
vector<int>edge[];
int vis[];
bool ok;
int str;
void bfs(int u,int flag){
queue<int>q;
q.push(u);
vis[u]=flag;
while(!q.empty()){
int tmp=q.front();
q.pop();
for(int i=;i<edge[tmp].size();i++){
int v=edge[tmp][i];
if(vis[v]==vis[tmp]){
ok=false;
return;
}
if(vis[v]==){
vis[v]=(-vis[tmp]);
q.push(v);
}
}
}
}
void init(){
ok=true;
memset(vis,,sizeof vis);
for(int i=;i<;i++){
edge[i].clear();
}
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF){
init();
for(int i=;i<m;i++){
scanf("%d%d",&a[i],&b[i]);
edge[a[i]].push_back(b[i]);
edge[b[i]].push_back(a[i]);
}
for(int i=;i<x;i++){
scanf("%d",&str);
if(vis[str]==-){
ok=false;
}
bfs(str,);
}
for(int i=;i<y;i++){
scanf("%d",&str);
if(vis[str]==){
ok=false;
}
bfs(str,-);
}
for(int i=;i<m;i++){
if(vis[a[i]]==&&vis[b[i]]==)
bfs(a[i],);
}
for(int i=;i<=n;i++){
if(vis[i]==){
ok=false;
break;
}
}
printf(ok?"YES\n":"NO\n");
}
return ;
}

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. NopCommerce添加事务机制

    NopCommerce现在最新版是3.9,不过依然没有事务机制.作为一个商城,我觉得事务也还是很有必要的.以下事务代码以3.9版本作为参考: 首先,IDbContext接口继承IDisposable接 ...

  2. MySQL_日期函数汇总

              如果转载,请注明博文来源: www.cnblogs.com/xinysu/   ,版权归 博客园 苏家小萝卜 所有.望各位支持!         关于MySQL日期时间函数,每回总 ...

  3. tomcat部署在centos6.8上的乱码问题

    web访问经常会莫名其妙的出现各种乱码问题.按照我自己的理解,设置一个charSet的过滤器,代码如下:import java.io.IOException; import javax.servlet ...

  4. kbhit()

    kbhit() 非阻塞的响应键盘输入时间   C++函数 功能和返回值:检查是否有键盘输入 ,有返回非0 ,无返回0 int khbit(void) 头文件: #include<conio.h& ...

  5. PHP浮点型(float)转换为整形(int)/round()保留小数点后几位

    round(x,y); x:需要转换的变量 y:保留几位小数 <?php echo round(3.112312321) //输出3 echo round(3.112312321,3) //输出 ...

  6. Android01-布局篇

    在Android中,共有五种布局方式,分别是:LinearLayout(线性布局),FrameLayout(帧布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局) ...

  7. ERROR! MySQL server PID file could not be found!的解决方法

    启动MySQL服务 [root@test vhosts]# /etc/init.d/mysqld restart 提示错误: ERROR! MySQL server PID file could no ...

  8. dmesg和addr2line 定位 segfault

    程序长时间运行崩溃,但是没有保存core dump消息.可以用下面的方法定位出程序出错位置: 1. 用dmesg查找出错的代码段地址 ip 000000000041ccec 发生错误时指令的地址, s ...

  9. django celery的分布式异步之路(一) 起步

    如果你看完本文还有兴趣的话,可以看看进阶篇:http://www.cnblogs.com/kangoroo/p/7300433.html 设想你遇到如下场景: 1)高并发 2)请求的执行相当消耗机器资 ...

  10. Spring MVC Ajax 嵌套表单数据的提交

    概述 在一些场景里,某个大表单里常常嵌套着一个或若干个小逻辑块,比如以下表单里"设计预审"中包括了一个子模块表单"拟定款项". 在这种情况下该怎么去设计实体类以 ...