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个随意的男孩配对.然后有些女孩是朋友,满足这个朋友圈里面的人.假设 ...
随机推荐
- Get Docker CE for Ubuntu
Docker 分为开源免费的 CE(Community Edition)版本和收费的 EE(Enterprise Edition)版本. 配置 Docker 的 apt 源 1. 安装包,允许 apt ...
- OJ 之 FATE
- FATE Crawling in process... Crawling failed Time Limit:100 ...
- 2014年的暑假ACM之旅!
致未来的我: 回到学校了,又开始了繁忙的生活! 虽然每天都不太轻松,但还是蛮有乐趣的,一起讨论某道题或者某种算法时挺开心的.@我.@姜维波.@曹彦宝.@李岩.@张永宏 继续这样下去,直到这个暑假的结束 ...
- 最短路N题Tram SPFA
#include <algorithm>#include <queue>#include <cstdio>#include <cstdlib>#inc ...
- EntityFramework 学习 一 Local Data
DBSet的Local属性提供简单的从context上下文获取当前已经被跟踪的实体(实体不能被标记为Deleted状态) using System.Data.Entity; class Program ...
- 每个程序员都应该了解的 CPU 高速缓存
每个程序员都应该了解的 CPU 高速缓存 英文原文:Memory part 2: CPU caches 来源:oschina [编者按:这是Ulrich Drepper写“程序员都该知道存储器”的第二 ...
- Codeforces 432D Prefixes and Suffixes:KMP + dp
题目链接:http://codeforces.com/problemset/problem/432/D 题意: 给你一个字符串s,让你找出所有既是前缀又是后缀的子串,并输出它们分别出现了多少次. 题解 ...
- ckeditor出现错误“从客户端(***)中检测到有潜在危险的 Request.Form值”的解决方法
ckeditor出现错误“从客户端(***)中检测到有潜在危险的 Request.Form值”的解决方法 页面中使用ckeditor,提交文章时总是出错,“从客户端(TextBox1="&l ...
- STL stl_uninitialized.h
stl_uninitialized.h // Filename: stl_uninitialized.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com ...
- Web实现音频、视频通信
Google开源实时通信项目WebRTC Google正式开源了WebRTC实时通信项目,希望浏览器厂商能够将该技术内建在浏览器中,从而使Web应用开发人员能够通过HTML标签和JavaScript ...