hdu 5971 Wrestling Match 二分图染色
题目链接
题意
\(n\)人进行\(m\)场比赛,给定\(m\)场比赛的双方编号;再给定已知的为\(good\ player\)的\(x\)个人的编号,已知的为\(bad\ player\)的\(y\)个人的编号。准则是每场比赛的两个选手必定一位来自\(good\ player\),另一位来自\(bad\ player\). 问是否可以据此将所有选手划分成两个阵营.
思路
// 题意和样例都很迷...
总的来说就是二分图染色,已经染好了若干个点,问能否顺利染成一个二分图。
但是不允许有孤立点。
具体操作上用\(dfs\)比较方便,因为图不连通,并查集不太好处理。
Code
#include <bits/stdc++.h>
#define maxn 2010
#define maxm 10010
bool flag;
int c[maxn], tot, ne[maxn], n, m, a, b, cnt;
struct Edge {
int to, ne;
Edge(int _to=0, int _ne=0): to(_to), ne(_ne) {}
}edge[maxm<<1];
void add(int u, int v) {
edge[tot] = Edge(v, ne[u]);
ne[u] = tot++;
}
using namespace std;
typedef long long LL;
void dfs(int u, int col) {
++cnt;
if (flag) return;
c[u] = col;
for (int i = ne[u]; ~i; i = edge[i].ne) {
int v = edge[i].to;
if (c[v]==-1) dfs(v, !col);
else if (c[v] == col) { flag = true; return; }
}
}
void work() {
int x, y;
tot = 0; memset(ne, -1, sizeof(ne)); memset(c, -1, sizeof c);
for (int i = 0; i < m; ++i) {
scanf("%d%d", &x, &y);
add(x, y), add(y, x);
}
for (int i = 0; i < a; ++i) scanf("%d", &x), c[x] = 0;
for (int i = 0; i < b; ++i) scanf("%d", &x), c[x] = 1;
flag = false;
for (int i = 1; i <= n; ++i) {
if (c[i] != -1) dfs(i, c[i]);
if (flag) { printf("NO\n"); return; }
}
for (int i = 1; i <= n; ++i) {
if (c[i] == -1) cnt = 0, dfs(i, 0);
if (flag || cnt == 1) { printf("NO\n"); return; }
}
printf("YES\n");
}
int main() {
while (scanf("%d%d%d%d", &n, &m, &a, &b) != EOF) work();
return 0;
}
hdu 5971 Wrestling Match 二分图染色的更多相关文章
- 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 ...
- HDU 5971"Wrestling Match"(二分图染色)
传送门 •题意 给出 n 个人,m 场比赛: 这 m 场比赛,每一场比赛中的对决的两人,一个属于 "good player" 另一个属于 "bad player" ...
- 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 ...
随机推荐
- Object-C知识点 (五) NSObject的继承关系
这篇文章主要介绍常用的继承自NSObject的类,方便朋友们查看和面试前查看使用!!! 结构图: 更多内容--> 博客导航 每周一篇哟!!! 有任何关于iOS开发的问题!欢迎下方留言!!!或者邮 ...
- rem和em的区别
原文链接:http://caibaojian.com/rem-vs-em.html rem 单位如何转换为像素值 当使用 rem 单位,他们转化为像素大小取决于页根元素的字体大小,即 html 元素的 ...
- LeetCode1089复写零
问题: 给你一个长度固定的整数数组 arr,请你将该数组中出现的每个零都复写一遍,并将其余的元素向右平移. 注意:请不要在超过该数组长度的位置写入元素. 要求:请对输入的数组 就地 进行上述修改,不要 ...
- constraint the design
- MySQL中CONCAT()的用法
MySQL中CONCAT()的用法 在日常开发过程中,特别是在书写接口的时候,经常会遇到字符串拼接的情况,比如在返回图片数据时,数据库里往往存储的是相对路径,而接口里一般是存放绝对地址,这就需要字符串 ...
- Linux学习-以最新核心版本编译 CentOS 7.x 的核心
为了某些缘故需要最新的 4.x.y 的核心版本来实作某些特定的功能时,那该 如何是好?没办法,只好使用最新的核心版本来编译你可以依照上面的程序来一个一个处理, 没有问题~不过,你也可以根据 ELRep ...
- Android兼容性测试CTS Verifier-环境搭建、测试执行、结果分析
CTS Verifier算是CTS的一部分,需要手动进行,主要用于测试那些自动测试系统无法测试的功能,比如相机.传感器等.由于硬件配置或其他原因,不同手机上部分测试项目被隐藏,也就是说CTS Veri ...
- flask-博客文章
提交和显示博客文章 文章模型 class Post(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer, primary_key= ...
- loj2275 「JXOI2017」颜色
枚举右端点,然后看左端点合法情况. 先预处理每个颜色 \(i\) 的最大出现位置 \(max_i\) 和最小出现位置 \(min_i\).对于枚举右端点在一个位置 \(i\),凡是 \(max_k & ...
- oracle主键自增长
这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下: create table simon_example ( id number(4) not null primary key, nam ...