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. Akka(27): Stream:Use case-Connecting Slick-dbStream & Scalaz-stream-fs2

    在以前的博文中我们介绍了Slick,它是一种FRM(Functional Relation Mapper).有别于ORM,FRM的特点是函数式的语法可以支持灵活的对象组合(Query Composit ...

  2. javascript插入before(),after()新DOM方法

    随着web的技术突飞猛进的发展.HTML5 ES6等新技术的发展,与此同时DOM等标准也在悄悄的进步,各大浏览器也在悄悄的发展适配新的属性和方法,今天我们来看看Javascript新的DOM的方法 二 ...

  3. 大数据 - Teradata学习体会

    引言 随着计算机系统在处理能力.存储能力等方面,特别是计算机软件技术的不断提高,使得信息处理技术得到飞速发展. 数据处理主要分为两大类:联机事物处理OLTP.联机分析处理OLAP.OLTP也就是传统的 ...

  4. AES加密解密——AES在JavaWeb项目中前台JS加密,后台Java解密的使用

    一:前言 在软件开发中,经常要对数据进行传输,数据在传输的过程中可能被拦截,被监听,所以在传输数据的时候使用数据的原始内容进行传输的话,安全隐患是非常大的.因此就要对需要传输的数据进行在客户端进行加密 ...

  5. Quartz学习——Quartz简单入门Demo(二)

    要学习Quartz框架,首先大概了解了Quartz的基本知识后,在通过简单的例子入门,一步一个脚印的走下去. 下面介绍Quartz入门的示例,由于Quartz的存储方式分为RAM和JDBC,分别对这两 ...

  6. GCD XOR uvalive6657

    GCD XORGiven an integer N, nd how many pairs (A; B) are there such that: gcd(A; B) = A xor B where1 ...

  7. C#实现基于ffmepg加虹软的人脸识别

    关于人脸识别 目前的人脸识别已经相对成熟,有各种收费免费的商业方案和开源方案,其中OpenCV很早就支持了人脸识别,在我选择人脸识别开发库时,也横向对比了三种库,包括在线识别的百度.开源的OpenCV ...

  8. 我真的知道JavaScript吗?

    JavaScript 说说JavaScript 接触JavaScript时间其实已经不短了,之前一直是半瓶酱油,东凑西凑的收集相关的知识.并没有完整系统的学习过JavaScript,觉得JavaScr ...

  9. HDU1257 最少拦截系统 (贪心+STL+二分)

    第一次在博客园写博客,好紧张 .博客搬家居然很多代码成了乱码,欲哭无泪,妈咪. 开学东西太多了吧,没时间写备注,有点时候只能贴个代码,以后有时间再加备注吧,只贴代码不是好习惯. 咦,贪心怎么写,我只会 ...

  10. 数据库表反向生成(二) Django ORM inspectdb

    在前一篇我们说了,mybatis-generator反向生成代码. 这里我们开始说如何在django中反向生成mysql model代码. 我们在展示django ORM反向生成之前,我们先说一下怎么 ...