Wrestling Match HDU - 5971(染色法判二分模板)

MySQL建表避坑指南:从字段类型到主键设计的生产级实践 MySQL建表是数据库开发的起点,本质是定义数据存储结构与访问契约。理解INT/BIGINT的符号性、VARCHAR在utf8mb4下的字节开销、DATETIME与TIMESTAMP的时区与范围差异,是避免线上事故的基础。主键选择直接影响聚簇索引性能和分布式扩展能力,而字符集(utf8mb4)、校对规则(utf8mb4_0900_ai_ci)和NOT NULL约束则决定了数据一致性与查询稳定性。这些设计决策不仅关乎语法正确性,更直接关联存储效率、并发吞吐与分库分表演进路径。本文聚焦真实生产场景中的建表逻辑、 阅读详情

Wrestling Match HDU - 5971

 Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is "good player”, the rest is "bad player”. Now, Xiao Ming is referee of the wrestling match and he has a list of the matches in his hand. At the same time, he knows some people are good players,some are bad players. He believes that every game is a battle between the good and the bad player. Now he wants to know whether all the people can be divided into "good player" and "bad player". 

Input
Input contains multiple sets of data.For each set of data,there are four numbers in the first line:N (1 ≤ N≤ 1000)、M(1 ≤M ≤ 10000)、X,Y(X+Y≤N ),in order to show the number of players(numbered 1toN ),the number of matches,the number of known “good players” and the number of known “bad players”.In the next M lines,Each line has two numbersa, b(a≠b) ,said there is a game between a and b .The next line has X different numbers.Each number is known as a “good player” number.The last line contains Y different numbers.Each number represents a known “bad player” number.Data guarantees there will not be a player number is a good player and also a bad player.
Output
If all the people can be divided into “good players” and “bad players”, output “YES”, otherwise output “NO”.
Sample Input

5 4 0 0
1 3
1 4
3 5
4 5
5 4 1 0
1 3
1 4
3 5
4 5
2

Sample Output

NO
YES

题意:给出n个人,m场比赛,x个人为good player,y个人为bad player,每场比赛两个人分分别为good和bad,问能否是一个二分图

分析:染色法判二分

code:

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int maxn = 25000 + 10;
typedef long long ll;
int n,m,x,y;
vector<int> G[maxn];
int color[maxn];

void init(){
    memset(color,0,sizeof(color));
    for(int i = 0; i < maxn; i++){
        G[i].clear();
    }
}

int dfs(int s){
    for(int i = 0; i < G[s].size(); i++){
        int v = G[s][i];
        if(color[v] == 0){
            color[v] = -color[s];
            if(!dfs(v))
                return 0;
        }
        else if(color[s] == color[v])
            return 0;
    }
    return 1;
}
int main(){
    while(scanf("%d%d%d%d",&n,&m,&x,&y) != EOF){
        init();
        int a,b;
        for(int i = 0; i < m; i++){
            scanf("%d%d",&a,&b);
            G[a].push_back(b);
            G[b].push_back(a);
        }
        for(int i = 0; i < x; i++){
            scanf("%d",&a);
            color[a] = 1;
        }
        for(int i = 0; i < y; i++){
            scanf("%d",&b);
            color[b] = -1;
        }
        if((x == 0 && y == 0) || n == 1){
            printf("NO\n");
            continue;
        }
        int ans = 1;
        for(int i = 1; i <= n; i++){
            if(color[i] != 0 && !dfs(i)){
                ans = 0;
                break;
            }
        }
        for(int i = 1; i <= n; i++){
            if(color[i] == 0){
                color[i] = 1;
                if(!dfs(i)){
                    ans = 0;
                    break;
                }
            }
        }
        if(ans == 1) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
DBeaver连接IoTDB避坑指南:手动配置JDBC驱动的完整流程(附问题排查) 本文提供了在DBeaver中手动配置Apache IoTDB JDBC驱动的完整流程与避坑指南。详细解析了从驱动创建、库文件添加(关键是指向整个lib目录)到连接测试的每一步,并重点针对常见的ClassNotFoundException、连接拒绝等错误提供了深度排查方案,帮助用户高效建立图形化管理连接。 阅读详情

相关推荐

AI 生成 CAN 通信测试用例实战

本文分享了AI辅助汽车电子测试用例编写的实战经验。通过某车企CAN网络测试项目案例,对比传统方式(需27天)与AI辅助方式(仅5天)的效率差异,展示81%的效率提升。文章详细介绍了从DBC文件提取信号信息的方法,包括DBC文件结构解析、信号定义说明,并提供了完整的Python解析脚本代码,可将信号信息导出为JSON或Excel格式,为后续AI批量生成测试用例奠定基础。

小明的博客 691

【HDU】5971-Wrestling Match 二分染色

http://acm.hdu.edu.cn/showproblem.php?pid=5971n个人m场比赛x个已确定的好人y个已确定的坏人。 每场比赛必有一好一坏。 是否能够将所有人划分成好人或者坏人。dfs 染色。先从 已确定的人 开始 染色。出现矛盾则NO。 然后对于不确定的人,枚举染色。出现矛盾则NO。 若最后还存在不确定的,那么就是 NO 否则就是 YES #include <i

西瓜不甜的博客 252

STM32F4使用CUBEMX ADC定时采样+DMA

STM32、FFT、ADC、TIM

m0_62379750的博客 4221

Wrestling Match (dfs乱搞染色)

Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is “good player”, the rest is “bad player”. Now, Xiao Ming is referee of the wrestling m...

a1046765624的博客 2484

实战解析:如何利用MDFEND与Weibo21数据集构建多领域假新闻检测系统

本文实战解析了如何利用MDFEND模型与Weibo21数据集构建多领域假新闻检测系统。文章深入剖析了MDFEND的领域门控与专家混合机制,并提供了从数据预处理、模型理解到训练部署的完整指南,旨在解决通用模型在不同领域新闻检测中的性能衰减问题,提升检测的准确性与适应性。

vulkan6gpu的博客 579

【ZZULIOJ】郑州轻工业大学oj题解整合

写在前面 关于ZZULIOJ题解 学习编程,想要巩固无非就是刷题或者做项目,然后因为我大一开始是刷郑轻的题目,就想着自己整合一下自己写的题目。既是复习也是笔记吧。 题解(内有题目描述) 1000 整数a+b 1001 植树问题 1002 简单多项式求值 1003 两个整数的四则运算 1004 三位数的数位分离 1005 整数幂 1006 求等差数列的和 1007 鸡兔同笼 1008 美元和人民币 1009 求平均分 1010 求圆的周长和面积 1011 圆柱体表面积 1012 求绝对值 1013 求两点间

蒟蒻乱写的博客 29万+

HDU - 5971-hdu5971-多源BFS

一开始以为是 传递闭包。因为太像了,但那个是二者之间的关系,没有传递这一说,这个更像是染色。。但是手头没有那本书。 然后就暴力写了一遍bfs,没有考虑已经确定的点对结果的影响。 一个点的影响忽略不计,可以通过反转。 但是两个点可能就无法反转了。wa了两次才想到了。。。 又以为是二分图匹配。感觉一个好人一个坏人是对应的。后来写了一会,感觉不对。 看了题解,是先把那些有确定关系的点给入队列,进

天与云与山与水 475

西门子CPU与汇川伺服通信与控制

第三方驱动器的配置内容和西门子的配置内容基本一致,基本上会一种即可知道其他品牌的配置默认报文,需要激活硬限位才能收到限位信号默认报文,原点信号不能实时输出到PLC;自定义报文,需要伺服端设置DIN点位。

大小曲奇的博客 1万+

hdu 5971 Wrestling Match

Wrestling Match Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1031Accepted Submission(s): 390 Problem Description Nowadays, at least on...

weixin_30385925的博客 245

YOLOv11n-seg 实战指南:从训练到模型部署的完整流程

本文提供了YOLOv11n-seg实例分割模型从环境准备、数据标注到模型训练、验证及最终部署的完整实战指南。详细讲解了如何准备多边形掩码数据、配置关键训练参数、解读分割核心评估指标,并重点介绍了将模型导出为ONNX等格式进行部署的流程与优化技巧,帮助开发者高效完成从开发到生产的全链路实践。

weixin_29062255的博客 552

【pprof】简要学习教程

基本介绍 pprof 是在做性能优化前的性能分析工具。 安装: go get -u github.com/google/pprof 分析工具 go tool pprof 是命令行指令,用于分析 Profiling 数据,源数据可以是 http 地址,也可以是已经 dump 下当 profile 文件;查看模式可以命令行交互模式,也可以是浏览器模式(-http 参数)。 两种应用 服务型应用 _ "net/http/pprof" 包,专用于采集 web 服务 运行数据的分析。即在运行的服务中通过 API .

码农印象 883

hdu5971—Wrestling Match(二分图染色+并查集)

  题意: 就是有n个人,m场PK,每一场PK都保证了一个是good,一个是bad,然后给了X个已经知道的好人的编号和Y个已经知道的坏人的编号。然后问能否分成两个阵营。 看样例: 给的PK能将1,2,4,5分成两大块,但是2何去何从是未知的,所以是NO。 下一个,2是good,所以能分成两大块。 思路: 1.利用染色的方法,看能否给已知的图进行染色,不成功说明矛盾输出no。 ...

20164225的博客 564

YOLOv11改进策略【Neck】| ASF-YOLO 注意力尺度序列融合模块改进颈部网络,提高小目标检测精度

ASF-YOLO是一种基于YOLO的新颖框架,结合了空间和尺度特征以实现准确和快速的分割。其中,注意力尺度序列融合模块。

Limiiiing的博客 4388

hdu5971 Wrestling Match(染色法判二分) 2016ACM/ICPC亚洲区大连站

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5971 Wrestling Match Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1100    Accepted Submi

一七得七 7万+

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Wrestling Match(HDU 5971)染色二分图

【代码】Wrestling Match(HDU 5971)染色二分图。

m0_60738889的博客 462

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

HDU 5971 Wrestling Match(染色法二分图 OR 并查集)

Wrestling Match Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1103    Accepted Submission(s): 421 Problem Description Nowadays, a

AI蜗牛之家 1576

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

HDU5971 Wrestling Match

Wrestling Match Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 498    Accepted Submission(s): 226 Problem Description Nowadays, at lea

要做ADC 374

HDU - 5971 Wrestling Match(染色法判断二分图)

Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is "good player”, the rest is "bad player”. Now, Xiao Ming is referee of the wrestling m...

vocaloid01的博客 304

2016 ICPC大连赛区 hdu5971 Wrestling Match

Wrestling Match Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 449    Accepted Submission(s): 206 Problem Description Nowadays, at

overload1997 406

HDU 5971 Wrestling Match(染色体法判断二分图)

Wrestling Match Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 375    Accepted Submission(s): 176 Problem Description Nowadays, at

Calm微笑 800

HDU 5971 Wrestling Match(二分图染色)

  题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5971        题意是有n个人,m个匹配,x个good player,y个bad player,每一个匹配都有一个good player和一个bad player,问能不能根据已知信息把这n个人分成两个集合。        思路就是用染色的方法去判断能不能构成一个二分图,我们首先将col...

Charles_Zaqdt的博客 288

HDU Problem - 5971 Wrestling Match(染色)

题目链接 Problem Description Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is “good player”, the rest is “bad player”. Now, Xiao Ming is...

Running Bit. 424

HDU 5971 icpc 大连 A Wrestling Match

Wrestling Match Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 68    Accepted Submission(s): 37 Problem Description Nowadays, at l

窦小雨的小点子 2421

hdu 5971 Wrestling Match(队列)

Wrestling Match Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 19    Accepted Submission(s): 13 Problem Description Nowadays, at least

saber_acher的博客 1467

hdu5917——Wrestling Match(二分图染色)

Problem Description Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is “good player”, the rest is “bad player”. Now, Xiao Ming is refere

Beyond the Sora 1607

2016ICPC大连站 A - Wrestling Match【二分图】

HDU 5971 Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is “good player”, the rest is “bad player”. Now, Xiao Ming is referee of the wr

Irish_Moonshine的博客 665
上一篇: A Simple Math Problem HDU - 5974(思维+数论)
下一篇: Detachment HDU - 5976(数学+逆元+前缀和前缀积)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值