传送门

•题意

  给出 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. spring boot 使用POI导出数据到Excel表格

    在spring boot 的项目经常碰到将数据导出到Excel表格的需求,而POI技术则对于java操作Excel表格提供了API,POI中对于多种类型的文档都提供了操作的接口,但是其对于Excel表 ...

  2. HBuilderX生成本地打包App资源

    http://ask.dcloud.net.cn/question/60254 概要 在HBuilderX中开发的应用可以提交到云端打包生成apk(Android平台)和ipa(iOS平台).如果本地 ...

  3. Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks【*组合数学】

    A. Kyoya and Photobooks time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. C++ 之手写strcpy

    char *strcpy(char* strDest, const char*strSrc){ assert(strDest != NULL&&strSrc != NULL); cha ...

  5. laravel学习文档

    https://github.com/barryvdh/laravel-debugbar Laravel 精选资源大全 http://laravelacademy.org/post/153.html ...

  6. 记一次goland的包导入问题

    昨天把go的GOPATH环境变量设置成了“/home/mi/app/gopath”,今天用goland新建的项目在/home/mi/go/src目录下,名字是studygolang,如下图. 结果导入 ...

  7. html(),val(),text()的区别

    .html(),.text(),.val() 三种方法都是用来读取选定元素的内容: .html()是用来读取元素的HTML内容(包括其Html标签): .text()用来读取元素的纯文本内 容,包括其 ...

  8. mongoDB端口启动失败原因

    删除以下文件: (所以数据会丢失,需要重新创建数据库)

  9. Contacts源码分析(一、概述)

    代码版本: Contact code version: 4.4.2 一 打开Log开关:如if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG ...

  10. 最短路-Dijkstra算法整理

    维基说的很全面:https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm 理解: 先设置访问数组vis[]和距离数组dist[],开始时把源点(sour ...