HDU 5971"Wrestling Match"(二分图染色)
•题意
给出 n 个人,m 场比赛;
这 m 场比赛,每一场比赛中的对决的两人,一个属于 "good player" 另一个属于 "bad player";
给出你 x 个已经确定的"good player" 和 y 个已经确定的 "bad player"。
问是否可以将这 n 个人划分成两类,其中一类属于 "good player",另一类属于 "bad player";
即不存在某人即属于 "good player" 又属于 "bad player";
如果能,输出 "YES",反之,输出 "NO";
•题解
对于每一场比赛的两人 $u,v$,连一条双向边 $u\rightarrow v\ ,\ v\rightarrow u$;
然后 DFS 染色。
先从已经确定的 $x+y$ 个人开始,染色与其相关的人,矛盾就输出 "NO";
然后对于不确定的人,枚举染色, 矛盾就输出 "NO";
如果不存在矛盾,输出 "YES";
•Code
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+;
const int M=1e4+; int n,m,x,y;
int num;
int head[N];
struct Edge
{
int to;
int next;
}G[M<<];
void addEdge(int u,int v)
{
G[num]={v,head[u]};
head[u]=num++;
}
int col[N];///0:Good , 1:bad
int g[N];
int b[N];
bool ok; void DFS(int u,int flag)
{
col[u]=flag;
for(int i=head[u];~i && !ok;i=G[i].next)
{
int v=G[i].to; if(col[v] == -)
DFS(v,flag^); if(col[v] == col[u])///u,v对立,如果出现col[u]=col[v],矛盾
ok=true;
}
}
char *Solve()
{
for(int i=;i <= x;++i)
{
int u=g[i];
ok=false;
if(col[u] == -)
DFS(u,);
if(ok || col[u] == )
return "NO";
}
for(int i=;i <= y;++i)
{
int u=b[i];
if(col[u] == -)
DFS(u,); if(ok || col[u] == )
return "NO";
}
for(int i=;i <= n;++i)
{
ok=false;
if(col[i] == - && head[i] != -)
DFS(i,); if(ok)
return "NO";
}
return "YES";
}
void Init()
{
num=;
for(int i=;i <= n;++i)
{
col[i]=-;
head[i]=-;
}
}
int main()
{
// freopen("C:\\Users\\hyacinthLJP\\Desktop\\C++WorkSpace\\in&&out\\contest","r",stdin);
while(~scanf("%d%d%d%d",&n,&m,&x,&y))
{
Init();
for(int i=;i <= m;++i)
{
int u,v;
scanf("%d%d",&u,&v);
addEdge(u,v);
addEdge(v,u);
}
for(int i=;i <= x;++i)
scanf("%d",g+i);
for(int i=;i <= y;++i)
scanf("%d",b+i);
puts(Solve());
}
return ;
}
HDU 5971"Wrestling Match"(二分图染色)的更多相关文章
- hdu 5971 Wrestling Match 二分图染色
题目链接 题意 \(n\)人进行\(m\)场比赛,给定\(m\)场比赛的双方编号:再给定已知的为\(good\ player\)的\(x\)个人的编号,已知的为\(bad\ player\)的\(y\ ...
- HDU 5971 Wrestling Match (二分图)
题意:给定n个人的两两比赛,每个人要么是good 要么是bad,现在问你能不能唯一确定并且是合理的. 析:其实就是一个二分图染色,如果产生矛盾了就是不能,否则就是可以的. 代码如下: #pragma ...
- 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 ...
- A - Wrestling Match HDU - 5971
Nowadays, at least one wrestling match is held every year in our country. There are a lot of people ...
- HDU 3081 Marriage Match II (二分图,并查集)
HDU 3081 Marriage Match II (二分图,并查集) Description Presumably, you all have known the question of stab ...
- HDU 5971 二分图判定
Wrestling Match Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU2444 :The Accomodation of Students(二分图染色+二分图匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 3081 Marriage Match II (网络流,最大流,二分,并查集)
HDU 3081 Marriage Match II (网络流,最大流,二分,并查集) Description Presumably, you all have known the question ...
随机推荐
- Can you find it? HDU-2141 (二分查找模版题)
Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need t ...
- js关闭或者刷新页面后执行事件
onbeforeunload 使用方法 window.onbeforeunload=function(){ return ''; } 有返回值才能弹出显示,或者有需要执行的事件也行.
- 第一周<导学>
导学 欧氏距离 平方 曼哈顿距离 一次方 马氏距离 协方差(先标准化再计算距离)\(d(x_{i},x_{j})=\sqrt{(x_{i}-x_{j})^{T}s^{-1}(x_{i}-x{j})}\ ...
- ls command not found
编辑profile文件没有写正确,导致在命令行下 ls等命令不能够识别. 在命令行下打入下面这段就可以了 export PATH=/usr/local/sbin:/usr/local/bin:/sbi ...
- Hdu 4597记忆化搜索
好久没有做题了,水平已经完全在学弟之下了. 一个吉林邀请赛最水的题目.:( 其实这题一看到数据范围,只可以想到思路,直接爆搜,加个记忆化. 这题虽然A了,但是我还是没太想清楚一些边界情况,心虚着A了. ...
- 【To Read】
Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle conta ...
- 搭建直播服务器,使用nginx与nginx-rtmp-module搭建流媒体服务器;
现在,一起学习一下如何自己搭建一个流媒体服务器吧! 本次搭建流媒体使用的环境是centos 7.0+nginx: 让我们一起开始奇妙的流媒体之旅吧! 1.下载nginx-rtmp-module: ng ...
- 异步操作async await
async函数的特点: 语义化强 里面的await只能在async函数中使用 await后面的语句可以是promise对象.数字.字符串等 async函数返回的是一个Promsie对象 await语句 ...
- 2019-4-29-dotnet-core-通过-frp-发布自己的网站
title author date CreateTime categories dotnet core 通过 frp 发布自己的网站 lindexi 2019-04-29 12:26:45 +0800 ...
- python 缺失值处理