A - Wrestling Match HDU - 5971
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的更多相关文章
- hdu 5971 Wrestling Match
题目链接: hdu 5971 Wrestling Match 题意:N个选手,M场比赛,已知x个好人,y个坏人,问能否将选手划分成好人和坏人两个阵营,保证每场比赛必有一个好人和一个坏人参加. 题解:d ...
- hdu 5971 Wrestling Match 判断能否构成二分图
http://acm.hdu.edu.cn/showproblem.php?pid=5971 Wrestling Match Time Limit: 2000/1000 MS (Java/Others ...
- HDU 5971 二分图判定
Wrestling Match Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5971 Wrestling Match (二分图)
题意:给定n个人的两两比赛,每个人要么是good 要么是bad,现在问你能不能唯一确定并且是合理的. 析:其实就是一个二分图染色,如果产生矛盾了就是不能,否则就是可以的. 代码如下: #pragma ...
- hdu 5971 Wrestling Match 二分图染色
题目链接 题意 \(n\)人进行\(m\)场比赛,给定\(m\)场比赛的双方编号:再给定已知的为\(good\ player\)的\(x\)个人的编号,已知的为\(bad\ player\)的\(y\ ...
- HDU 5971"Wrestling Match"(二分图染色)
传送门 •题意 给出 n 个人,m 场比赛: 这 m 场比赛,每一场比赛中的对决的两人,一个属于 "good player" 另一个属于 "bad player" ...
- 【HDOJ5971】Wrestling Match(二分图,并查集)
题意:有n个人,m场比赛,x个人为good player,y个人为bad player, 每场比赛两个人分分别为good和bad,问good和bad是否会冲突 1 ≤ N≤ 1000,1 ≤M ≤ 1 ...
- 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 ...
- hdoj 5971
Wrestling Match Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
随机推荐
- cglib代理
简介: github地址:https://github.com/cglib/cglib,可以访问这个地址查看cglib源码和相关文档. 简单的摘录了wiki上关于cglib的描述: cglib is ...
- 个人从源码理解JIT模式下angular编译AppModule的过程
承接上文.笔者之前将一个angular项目的启动过程分为了两步: 创建平台得到 PlatformRef ,以及执行平台引用提供的方法编译根模块 AppModule .本文就将着眼于创建好的平台,从an ...
- #pragma编译指令
#pragma alignment#pragma anon_struct#pragma argsused#pragma checkoption#pragma codeseg#pragma commen ...
- linux free命令解读
$ free -m total used free shared buffers cached Mem: 1002 769 232 0 62 421 -/+ buffers/cache: 286 71 ...
- hdu1540 区间操作,合并,模板题
During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...
- JS在可编辑的div中的光标位置插入内容或表情
<input type="button" value="插入字符" onclick="document.getElementById('test ...
- C#钩子类 几乎捕获键盘鼠标所有事件
using System; using System.Text; using System.Runtime.InteropServices; using System.Reflection; usin ...
- WPF 中的 Pack URI地(资源文件加载)
参考资源网http://msdn.microsoft.com/zh-cn/library/aa970069.aspx#Absolute_vs_Relative_Pack_URIs 在 Windows ...
- 初学者易上手的SSH-struts2 04值栈与ognl表达式
什么是值栈?struts2里面本身提供的一种存储机制,类似于域对象,值栈,可以存值和取值.,特点:先进后出.如果将它当做一个容器的话,而这个容器有两个元素,那么最上面的元素叫做栈顶元素,也就是所说的压 ...
- visual Studio 无法调试,提示程序跟踪已退出
今天在打码出现了vs无法调试,我在网上查了很久没有发现一个方法. vs点击启动时,出现了一下提示 程序"[12648] *.vshost.exe: 程序跟踪"已退出,返回值为 0 ...