题意:有n个人,m场比赛,x个人为good player,y个人为bad player,

每场比赛两个人分分别为good和bad,问good和bad是否会冲突

1 ≤ N≤ 1000,1 ≤M ≤ 10000

思路:二分图

根据已有的点暴力遍历,判有没有冲突即可

并查集也能写,队友写的搜索

 #include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
using namespace std;
typedef long long int lint; const int MAXN = 1e3 + ;
const int MAXM = 1e4 + ; vector<int> g[MAXN];
queue<int> a,b; int n,m,x,y;
int color[MAXN]; void init(){
memset(color,-,sizeof(color));
for(int i = ; i <= n; ++i){ g[i].clear();}
while(!a.empty()){ a.pop();}
while(!b.empty()){ b.pop();}
} bool solve(){
while(!a.empty() || !b.empty()){
while(!a.empty()){
int now = a.front(); a.pop();
for(int i = ; i < g[now].size(); ++i){
if(color[g[now][i]] == -){
color[g[now][i]] = ; b.push(g[now][i]);
}else if(color[g[now][i]] == ){
return false;
}
}
}
while(!b.empty()){
int now = b.front(); b.pop();
for(int i = ; i < g[now].size(); ++i){
if(color[g[now][i]] == -){
color[g[now][i]] = ; a.push(g[now][i]);
}else if(color[g[now][i]] == ){
return false;
}
}
}
}
return true;
} int main(){
while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF){
init();
for(int i = ; i <= m; ++i){
int u,v; scanf("%d%d",&u,&v);
g[u].push_back(v); g[v].push_back(u);
}
for(int i = ; i <= x; ++i){
int num; scanf("%d",&num); a.push(num); color[num] = ;
}
for(int i = ; i <= y; ++i){
int num; scanf("%d",&num); b.push(num); color[num] = ;
}
if(!solve()){
printf("NO\n"); continue;
}
bool flag = true;
for(int i = ; i <= n; ++i){
if(color[i] == - && g[i].size() != ){
a.push(i);
if(!solve()){
flag = false; break;
}
}else if(color[i] == - && g[i].size() == ){
flag = false; break;
}
}
if(!flag){
printf("NO\n"); continue;
}else{
printf("YES\n"); continue;
}
}
return ;
}

【HDOJ5971】Wrestling Match(二分图,并查集)的更多相关文章

  1. hdu 5971 Wrestling Match 二分图染色

    题目链接 题意 \(n\)人进行\(m\)场比赛,给定\(m\)场比赛的双方编号:再给定已知的为\(good\ player\)的\(x\)个人的编号,已知的为\(bad\ player\)的\(y\ ...

  2. bzoj1854 游戏题解(二分图/并查集)

    1854: [Scoi2010]游戏 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 5547  Solved: 2229[Submit][Status] ...

  3. NOIp 2010/Luogu P1525 关押罪犯 【二分图/并查集】 By cellur925

    题目传送门 感想:相信自己的想法!继续挖掘! 读完题目后:看到的最大值最小?二分答案啊!再仔细一看:wi达到了1e9,二分可能费点劲.(其实真的是可以的)而且check函数貌似并没有什么行之有效的写法 ...

  4. HDU 3277 Marriage Match III(并查集+二分答案+最大流SAP)拆点,经典

    Marriage Match III Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  5. HDU 5971 Wrestling Match (二分图)

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

  6. HDU 3081 Marriage Match II (二分图,并查集)

    HDU 3081 Marriage Match II (二分图,并查集) Description Presumably, you all have known the question of stab ...

  7. HDU3081:Marriage Match II (Floyd/并查集+二分图匹配/最大流(+二分))

    Marriage Match II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. HDU 3081:Marriage Match II(二分图匹配+并查集)

    http://acm.hdu.edu.cn/showproblem.php?pid=3081 题意:有n个男生n个女生,他们只有没有争吵或者女生a与男生A没有争吵,且女生b与女生a是朋友,因此女生b也 ...

  9. HDU-3081-Marriage Match II 二分图匹配+并查集 OR 二分+最大流

    二分+最大流: 1 //题目大意:有编号为1~n的女生和1~n的男生配对 2 // 3 //首先输入m组,a,b表示编号为a的女生没有和编号为b的男生吵过架 4 // 5 //然后输入f组,c,d表示 ...

随机推荐

  1. linux 使用wget下载https连接地址cannot verify github.com's certificate

    使用linux的wget下载时候会出现网站没有证书警告的问题, 例如下载git时,可以使用wget https://github.com/git/git/archive/v2.3.0.zip --no ...

  2. C# 使用Epplus导出Excel [4]:合并指定行

    C# 使用Epplus导出Excel [1]:导出固定列数据 C# 使用Epplus导出Excel [2]:导出动态列数据 C# 使用Epplus导出Excel [3]:合并列连续相同数据 C# 使用 ...

  3. 浅谈JavaScript中的正则表达式(适用初学者观看)

    浅谈JavaScript中的正则表达式 1.什么是正则表达式(RegExp)? 官方定义: 正则表达式是一种特殊的字符串模式,用于匹配一组字符串,就好比用模具做产品,而正则就是这个模具,定义一种规则去 ...

  4. 如何用 CSS 和 D3 创作一个无尽的六边形空间

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/NBvrWL 可交互视频 此视频是可 ...

  5. dict 方法总结整理

    #!/usr/bin/env python __author__ = "lrtao2010" #Python 3.7.0 字典常用方法 #字典的key是唯一的,且不能被修改,val ...

  6. Three displays CodeForces - 987C (dp)

    C. Three displays time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. NPM包的安装及卸载

    NPM全名:node package manager,是node包管理工具,负责安装.卸载.更新等.新版的NodeJS已经集成了npm.所以装好NodeJS的同时,npm也已经装好了! 可以用cmd命 ...

  8. hdu 1011 Starship Troopers(树形背包)

    Starship Troopers Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. IDEA-常用插件,使用FindBugs寻找bug,代码分析

    bug无处不在,但是我们总希望少一点bug. 最近发现了一款好用的寻找bug的插件,特此记下. 一.安装 路径:File-->Settings-->Plugins-->Browse ...

  10. 自建NAS如何使用大于2TB的硬盘(从分区开始)

    目录 自建NAS如何使用大于2TB的硬盘(从分区开始) 对分区进行格式化 挂载到某一目录(需设置开机自动挂载) 上传文件测试: 补充 自建NAS如何使用大于2TB的硬盘(从分区开始) 需求说明: 自建 ...