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 ...
随机推荐
- mysql 定时任务job
mysql 定时任务job 1.通过show EVENTS显示当前定义的事件 2.检查event_scheduler状态:SHOW VARIABLES LIKE 'event_scheduler' 3 ...
- 微信小程序传值取值的几种方法
一,列表index下的取值 实现方式是:data-index="{{index}}"挖坑及e.currentTarget.dataset.index来填坑即可 1.1生成值 < ...
- CE软件修改器
下载地址: 链接:https://pan.baidu.com/s/1WQa5epfmLW92xk0XY10pqw 提取码:jt3k 喜欢请点赞
- NOIp2017囤题计划
马上就要NOIp2017了,应该囤些题目吧…… 好的这只是一个开始 upd - 11.5 1.p1576 最小花费 无向图,dijisktra 2.p1339 [USACO09OCT]热浪Heat W ...
- spring boot自动配置实现
自从用了spring boot,都忘记spring mvc中的xml配置是个什么东西了,再也回不去.为啥spring boot这么好用呢, 约定大于配置的设计初衷, 让我们只知道维护好applicat ...
- 201621123080《Java程序设计》第十一周学习总结
201621123080<Java程序设计>第十一周学习总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 ...
- python入门:in 的用法(它在不在这个字符串里面)
#!/usr/bin/env python # -*- coding:utf-8 -*- #in 的用法(它在不在这个字符串里面) #ret(返回,译音:ruai特) #给s赋值为字符串“Alex S ...
- thinkphp5开发restful-api接口学习 笔记二
目录 第4节 为api项目搭建数据库 第5节 使用markdown书写接口文档 第6节(判断数据库中是否有此用户) 第7节 为项目配置URL 需求分析 配置主域名和二级域名 使用tp5路由进行URL解 ...
- python网络-Socket之TCP编程(26)
一.TCP简介 1.TCP介绍 TCP协议,传输控制协议(英语:Transmission Control Protocol,缩写为 TCP)是一种面向连接的.可靠的.基于字节流的传输层通信协议. TC ...
- w3resource_MySQL练习: Aggregate_functions
w3resource_MySQL练习题:Aggregate_functions 1. Write a query to list the number of jobs available in t ...