传送门

•题意

  给出 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"(二分图染色)的更多相关文章

  1. hdu 5971 Wrestling Match 二分图染色

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

  2. HDU 5971 Wrestling Match (二分图)

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

  3. hdu 5971 Wrestling Match

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

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

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

  5. A - Wrestling Match HDU - 5971

    Nowadays, at least one wrestling match is held every year in our country. There are a lot of people ...

  6. HDU 3081 Marriage Match II (二分图,并查集)

    HDU 3081 Marriage Match II (二分图,并查集) Description Presumably, you all have known the question of stab ...

  7. HDU 5971 二分图判定

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

  8. HDU2444 :The Accomodation of Students(二分图染色+二分图匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. HDU 3081 Marriage Match II (网络流,最大流,二分,并查集)

    HDU 3081 Marriage Match II (网络流,最大流,二分,并查集) Description Presumably, you all have known the question ...

随机推荐

  1. django 结合 bootstrap 使用

    git clone https://github.com/dyve/django-bootstrap3.git 要运行demo,需要在demo 中为其增加一个符号链接 bootstrap3 到上层目录 ...

  2. Mybatis - plus 配置与运用

    Mybatis - plus mybatis-plus 官方文档  1.配置 引入对应的文件包,spring boot + mybatis 需添加依赖文件如下: <dependencies> ...

  3. 【水滴石穿】douban-movies-react-native

    这个项目的话,倒是可以做一个支架页面,就是你需要什么东西,你就可以在里面加,不过也是比较难的地方 就是数据流,数据处理的部分.react可以处理数据的方式很多,没有见过类似于古老的vue时候可以使用的 ...

  4. 客户端connect返回错误显示No route to host

    务器程序运行起来后,客户端connect返回错误显示No route to host,但是两台机子能ping通 是firewall的问题, services iptables stop应该就ok了

  5. Oracle中事物处理--事物隔离级别

    n  事物隔离级别 概念:隔离级别定义了事物与事物之间的隔离程度. ANSI/ISO SQL92标准定义了一些数据库操作的隔离级别(这是国际标准化组织定义的一个标准而已,不同的数据库在实现时有所不同) ...

  6. 阿里云区块链共创会:BaaS正式商业化 广邀合作伙伴共建生态

    摘要: 阿里云宣布区块链服务Hyperledger Fabric版正式商业化,并发布生态合作伙伴计划. 2019年3月29日,阿里云区块链于深圳召开正式商业化共创会,宣布区块链服务Hyperledge ...

  7. 威胁快报|首爆,新披露Jenkins RCE漏洞成ImposterMiner挖矿木马新“跳板”

    简介 阿里云安全于近日捕获到一起使用Jenkins RCE漏洞进行攻击的挖矿事件.除挖矿外,攻击者还曾植入具有C&C功能的tsunami木马,也预留了反弹shell的功能,给用户带来极大安全隐 ...

  8. TCPThree_C杯 Day2

    T1 我已经被拉格朗日插值蒙蔽了双眼,变得智障无比. 第一反应就是拉格朗日插值,然后就先放下了它. 模数那么小,指数那么大,这是一套noip模拟题,拉格朗日,你脑袋秀逗了? 无脑暴力20分贼开心. 正 ...

  9. C++之MD5加密(签名)

    md5.h : #include <stdio.h> #include <stdlib.h>#include <time.h> #include <strin ...

  10. 在oracle中操作数据——使用特点的格式插入日期 sql函数的使用——日期函数

    日期函数用于处理date类型的数据,默认情况下的日期格式是dd-mm-yy即12-7月-78 (1)sysdate:该函数返回系统时间 (2)add_months(d,n) (3)last_day(d ...