HDU 5971 Wrestling Match (二分图)
题意:给定n个人的两两比赛,每个人要么是good 要么是bad,现在问你能不能唯一确定并且是合理的。
析:其实就是一个二分图染色,如果产生矛盾了就是不能,否则就是可以的。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} vector<int> G[maxn];
set<int> sets;
int a[maxn], b[maxn];
int color[maxn];
bool ok; void dfs(int u, int x){
if(!ok) return ;
for(int i = 0; i < G[u].size(); ++i){
int v = G[u][i];
if(color[v] && color[v] + color[u] != 3){
ok = false; return ;
}
if(color[v]) continue;
color[v] = x;
dfs(v, 3 - x);
}
} int main(){
int x, y;
while(scanf("%d %d %d %d", &n, &m, &x, &y) == 4){
for(int i = 1; i <= n; ++i) G[i].clear();
sets.clear();
for(int i = 0; i < m; ++i){
int u, v;
scanf("%d %d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
sets.insert(u);
sets.insert(v);
}
memset(color, 0, sizeof color);
for(int i = 0; i < x; ++i){
scanf("%d", a+i);
sets.insert(a[i]);
}
for(int i = 0; i < y; ++i){
scanf("%d", b+i);
sets.insert(b[i]);
}
if(sets.size() != n){ puts("NO"); continue; }
ok = true;
for(int i = 0; i < x && ok; ++i){
if(color[a[i]] && color[a[i]] != 1) ok = false;
color[a[i]] = 1;
dfs(a[i], 2);
}
for(int i = 0; i < y && ok; ++i){
if(color[b[i]] && color[b[i]] != 2) ok = false;
color[b[i]] = 2;
dfs(b[i], 1);
}
for(int i = 1; i <= n && ok; ++i) if(!color[i]){
color[i] = 1;
dfs(i, 2);
}
printf("%s\n", ok ? "YES" : "NO");
}
return 0;
}
HDU 5971 Wrestling Match (二分图)的更多相关文章
- hdu 5971 Wrestling Match 二分图染色
题目链接 题意 \(n\)人进行\(m\)场比赛,给定\(m\)场比赛的双方编号:再给定已知的为\(good\ player\)的\(x\)个人的编号,已知的为\(bad\ player\)的\(y\ ...
- 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 ...
- HDU 3081 Marriage Match II (网络流,最大流,二分,并查集)
HDU 3081 Marriage Match II (网络流,最大流,二分,并查集) Description Presumably, you all have known the question ...
- HDU 3277 Marriage Match III(二分+最大流)
HDU 3277 Marriage Match III 题目链接 题意:n个女孩n个男孩,每一个女孩能够和一些男孩配对,此外还能够和k个随意的男孩配对.然后有些女孩是朋友,满足这个朋友圈里面的人.假设 ...
随机推荐
- Spark操作算子本质-RDD的容错
Spark操作算子本质-RDD的容错spark模式1.standalone master 资源调度 worker2.yarn resourcemanager 资源调度 nodemanager在一个集群 ...
- Sqoop-1.4.4工具import和export使用详解
转自:http://blog.csdn.net/wodatoucai/article/details/46343291 Sqoop可以在HDFS/Hive和关系型数据库之间进行数据的导入导出,其中主要 ...
- Java -- 封装访问控制级别,包, instanceof 运算符, 初始化块
1. 可以用 package name1.name2; 显式的定义包名, *.class文件位置应该对应包 name1 name2 的目录下. 2. instanceof 运算符 Object obj ...
- Linux - xshell上传文件报错乱码
xshell上传文件报错乱码,解决方法 rz -be 回车 下载sz filename
- Tab支持的DHTML Window控件
带有Tab标签支持的DHTML Window控件.它使用cookies来“记忆”窗体大小,位置,哪个Tab选项被选中,window堆叠顺序.代码下载地址:http://www.huiyi8.com/ ...
- 分享知识-快乐自己:揭秘HBase
揭秘HBase: 一):大数据(hadoop)初始化环境搭建 二):大数据(hadoop)环境搭建 三):运行wordcount案例 四):揭秘HDFS 五):揭秘MapReduce 六):揭秘HBa ...
- 分享知识-快乐自己:Liunx-大数据(Hadoop)初始化环境搭建
大数据初始化环境搭建: 一):大数据(hadoop)初始化环境搭建 二):大数据(hadoop)环境搭建 三):运行wordcount案例 四):揭秘HDFS 五):揭秘MapReduce 六):揭秘 ...
- 十五 Django框架,缓存
由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存,缓存将一个某个views的返回值保存至内存或者memcache中,5 ...
- Mysql存储过程及调用
存储过程: 存储过程是SQL 语句和可选控制流语句的预编译集合,以一个名称存储并作为一个单元处理.存储过程存储在数据库内,可由应用程序通过一个调用执行,而且允许用户声明变量.有条件执行以及其它强大的 ...
- Python基础-数据写入execl
import xlwt book = xlwt.Workbook()#创建一个excel sheet = book.add_sheet('lanxia')#添加一个sheet页 title = ['姓 ...