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个随意的男孩配对.然后有些女孩是朋友,满足这个朋友圈里面的人.假设 ...
随机推荐
- Linux电源管理(5)_Hibernate和Sleep功能介绍【转】
本文转载自:http://www.wowotech.net/pm_subsystem/std_str_func.html 1. 前言 Hibernate和Sleep两个功能是Linux Generic ...
- 启动Hadoop时DFSZKFailoverController没有启动
在启动Hadoop成功后,并没有报错信息,jps查看进程,发现DFSZKFailoverController没有启动成功,后来发现是因为防火墙的原因,关掉重试就OK了 systemctl stop f ...
- spring boot拦截器
实现自定义拦截器只需要3步: 1.创建我们自己的拦截器类并实现 HandlerInterceptor 接口. 2.创建一个Java类继承WebMvcConfigurerAdapter,并重写 addI ...
- 手把手编写PHP框架 深入了解MVC运行流程
1 什么是MVC MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Controller ...
- jQuery Cloud Zoom:图片放大镜插件 破解插件
/* Cloud Zoom 10 Site License (CZ01-10). Version 3.1 rev 1312051822 */ (function(e) { function s(a) ...
- 浏览器对应的selenium版本问题
在selenium+python环境下查看selenium版本方法: cmd下输入:pip show selenium 卸载selenium版本: cmd下输入:pip uninstall selen ...
- 数据库中的id不会自动 替换,这个应该处理吗。怎么处理,那个是唯一主键
- JavaWEB - JSP 指令
- TypeError: 'str' object is not callable
Python报错TypeError: 'str' object is not callable
- windows 7下mingw+msys编译ffmpeg
windows 7下mingw+msys编译ffmpeg 1-->下载安装MingW,mingw-get-inst-20120426.exe http://sourceforge.ne ...