题意:有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. Makefile 编写实例

    make命令常用的三个选项: 1.-k:它的作用是让make命令在发现错误的时候仍然继续执行.我们可以利用这个选项在一次操作中发现未编译成功的源文件. 2.-n:它的作用是让make命令输出将要执行的 ...

  2. C#4.0中的dynamic关键字和ExpandoObject对象

    dynamic最大的特点我想莫过于在它的类型在运行时才确定,这也是它与往静态类型关键字的最大区别.如果你在你的代码操作中用到了dynamic关键字去定义一个变量时,那么这个变量在编译的时候编译器不会对 ...

  3. C# 替换去除HTML标记方法(正则表达式)

    [from] http://blog.csdn.net/sgear/article/details/6263848/// <summary> /// 将所有HTML标签替换成"& ...

  4. MySQL查询时,查询结果如何按照where in数组排序

    MySQL查询时,查询结果如何按照where in数组排序 在查询中,MySQL默认是order by id asc排序的,但有时候需要按照where in 的数组顺序排序,比如where in的id ...

  5. 【mac】【转发】Mac系统升级后,按大小写键没反应了,切换大小写的灯不亮了

    Mac系统升级后发现caps lock 锁定大小写的键,失灵了,居然可以用来切换输入法了,经过一排查后, 使用以下几种方法处理: 方式一:长按 caps lock 键,来切换大小写 方式二:caps ...

  6. w3resource_MySQL练习: Aggregate_functions

    w3resource_MySQL练习题:Aggregate_functions   1. Write a query to list the number of jobs available in t ...

  7. LeetCode(5)Longest Palindromic Substring

    题目 Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...

  8. POJ:2632-Crashing Robots

    Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Description In a modernized warehouse, robot ...

  9. BNU 3692 I18n 模拟

    题意: 在一篇文章中,单词可以缩写.例如单词Internationalization可以缩写为I18n,缩写的两端是原单词的首尾字母,中间的数字是被省略的字母的个数. 现在给你一篇缩写的文章,输出展开 ...

  10. Hive学习笔记(二)

    Hive内部表跟外部表之间的区别 创建外部表 先删除上面创建的表,指定location 此时在hdfs根目录下就有一个hivedata文件夹 上传文本数据到hivedata目录下 查询表中数据 删除上 ...