题目链接

题意

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

  1. HDU 5971 Wrestling Match (二分图)

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

  2. hdu 5971 Wrestling Match

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

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

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

  4. HDU 5971"Wrestling Match"(二分图染色)

    传送门 •题意 给出 n 个人,m 场比赛: 这 m 场比赛,每一场比赛中的对决的两人,一个属于 "good player" 另一个属于 "bad player" ...

  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. 瀑布流封装(仿写UITableView)

    本篇文章将会仿照苹果系统提供的UITableView类,封装一个瀑布流效果的控件!!! 该控件和系统的UITableView是相同级别的 (继承自系统的UIScrollView) GitHub中Dem ...

  2. matplotlib subplot 子图

    总括 MATLAB和pyplot有当前的图形(figure)和当前的轴(axes)的概念,所有的作图命令都是对当前的对象作用.可以通过gca()获得当前的axes(轴),通过gcf()获得当前的图形( ...

  3. codis 配置

    #修改dashboard.toml: coordinator_name = "zookeeper" coordinator_addr = "192.168.56.101: ...

  4. Ansible的使用和模块化深入

    Ansible配置 配置文件:/etc/ansible/ansible.cfg [default] 默认配置 inventory = /etc/ansible/hosts主机清单 library = ...

  5. DC 课程内容

  6. Python基础学习总结__Day2

    一.模块初始 1.标准库模块: (1) Os模块 ① 和操作系统交互:例:执行命令代码 (2) Sys模块 ① 脚本+参数——>结果 2.第三方库模块:Django,Mysql... 存在E:\ ...

  7. 【Arduino开发板刷Bootloader01】

    其接线方式就是:   Programmer(工具开发板)                Being programmed(目标开发板)                              Vcc ...

  8. Linux学习-额外(单一)核心模块编译

    编译前注意事项 由于我们的核心原本就有提供很多的核心工具给硬件开发商来使用, 而硬件开发商也需要针对核心 所提供的功能来设计他们的驱动程序模块,因此, 我们如果想要自行使用硬件开发商所提供的模块 来进 ...

  9. Linux学习-透过 systemctl 管理服务

    透过 systemctl 管理单一服务 (service unit) 的启动/开机启动与观察状态 一般来说,服务的启动有两个阶段,一 个是『开机的时候设定要不要启动这个服务』, 以及『你现在要不要启动 ...

  10. bash循环for/while/until

    shell流程控制之一:for循环     for VAR in LIST; do         STATEMENT1         ...     done         例:         ...