A Bug's Life

A Bug's Life ACM简单并查集 CSDN博客 问题描述 A Bug’s Life Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of ... 阅读详情

Background
Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their backs.
Problem
Given a list of bug interactions, decide whether the experiment supports his assumption of two genders with no homosexual bugs or if it contains some bug interactions that falsify it.
Input
The first line of the input contains the number of scenarios. Each scenario starts with one line giving the number of bugs (at least one, and up to 2000) and the number of interactions (up to 1000000) separated by a single space. In the following lines, each interaction is given in the form of two distinct bug numbers separated by a single space. Bugs are numbered consecutively starting from one.
Output
The output for every scenario is a line containing “Scenario #i:”, where i is the number of the scenario starting at 1, followed by one line saying either “No suspicious bugs found!” if the experiment is consistent with his assumption about the bugs’ sexual behavior, or “Suspicious bugs found!” if Professor Hopper’s assumption is definitely wrong.
Sample Input
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
Sample Output
Scenario #1:
Suspicious bugs found!

Scenario #2:
No suspicious bugs found!
Hint
Huge input,scanf is recommended.
a到b表示a喜欢b,然后问你这些虫子里有没有同性恋(只有雌雄两个)。
食物链精简版。就是看看他在不在一个树上,在的话,看看和祖先是什么关系,不在就合并。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
int n, m;
bool r[2005];
int p[2005];
void init()
{
    for (int i = 1; i <= n; i++)
    {
        p[i] = i; r[i] = 0;
    }
}
int find(int x)
{
    if (x != p[x])
    {
        int fx = find(p[x]);
        if (r[x] == r[p[x]])r[x] = 0;
        else r[x] = 1;
        p[x] = fx;
    }
    return p[x];
}
void union_set(int x, int y)
{
    int fx = find(x);
    int fy = find(y);
    p[fx] = fy;
    if (r[x] == r[y])r[fx] = 1;
    else r[fx] = 0;
}
int main()
{
#ifdef LOCAL
    freopen("C:\\Users\\巍巍\\Desktop\\in.txt", "r", stdin);
    //freopen("C:\\Users\\巍巍\\Desktop\\out.txt","w",stdout);
#endif // LOCAL
    int t, flag, kase = 1;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d%d", &n, &m);
        init();
        flag = 0;
        while (m--)
        {
            int x, y;
            scanf("%d%d", &x, &y);
            int fx = find(x);
            int fy = find(y);
            if (fx == fy&&r[x] == r[y])flag = 1;
            else if (fx != fy)
            {
                union_set(x, y);
            }
        }
        printf("Scenario #%d:\n", kase++);
        if (flag)
            printf("Suspicious bugs found!\n");
        else
            printf("No suspicious bugs found!\n");
            printf("\n");
    }
    return 0;
}
【代码超详解】POJ 2492 A Bug's Life(并查集) 一、题目描述 二、算法分析说明与代码编写指导 类似题目:POJ 1182 食物链 题解 设有 m 只虫子,n 次观察到的交尾。 虫子 u 和 v 只有性别不同时才可以交尾,那么有两种情况:u♂ × v♀、u♀ × v♂。 每一只虫子可能是雄性也可能是雌性,这两种情况都要进行并查集的合并,方法是 merge (u, v + m),merge(u + m, v)。 查询两只虫子是否是同性的时候,只需... 阅读详情

相关推荐

Centos7.6下安装Zabbix6

一、

Overmaster博客 1914

poj2492 A Bug's Life 并查集

poj2492 并查集

wilver的博客 604

物料主数据管理难在哪?基于AI算法的数据清洗工具了解一下

企企通打造的一套以AI模型和算法为核心的产品及服务,可针对各类企业的不同主数据痛点难点,提供多种解决方案,能够快速完成物料主数据清洗、识别、匹配、梳理,满足一物一码、分类梳理、一品多商、多维度比价、精准寻源选品、建立标准物料库、供应商及客户主数据清洗等业务场景需求。随着AI技术的快速发展,智能算法在数据清洗领域的应用越来越广泛,越来越多的数据清洗工作已经开始交由智能算法完成,通过自动化的方式处理大量数据,识别和纠正错误,填补缺失值,检测异常值,以及执行其他数据预处理任务,并提高效率并减少人为错误。

QQT_qqt的博客 1372

【 POJ - 2492 】F - A Bug‘s Life (种类/分类 并查集)

题目: Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their inte

黑桃 227

NFS服务器配置与autofs自动挂载

NFS服务器配置autofs自动挂载 环境: hostname ip OS server 192.168.220.138 centos7 client 192.168.220.139 centos7 一、NFS概述 NFS(Network File System)网络文件系统。最大功能就是通过网络,让不同的机器、不同的操作系统可以共享彼此的文件。 二、端口 [root@se...

DoloresOOO的博客 1037

centos7部署mysql8.0.35,主从复制,主主集群

centos7 linux部署mysql,主从复制,主主模式

zaixiaqin的博客 1997

A Bug's Life(并查集)

Problem Description Background  Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with b

sdau20163940的博客 690

stm32 + freertos + c++混合编程方法

其他一些资料上面,c++配置成--cpp11或者-cpp 都是把工程配置成c++。三、添加cpp文件,我们调用cpp文件里面的接口函数,不需要修改main.c后缀名。2、配置工程编译时候是--c99,是因为工程里面FreeRTOS是c语言,c++模式会报错。我们这里是默认c,编写的c++文件,单独选择--cpp编译,这在后面配置!c++是面向对象编程,对于一些项目来说,c++编程更加合适!stm32cubemax配置,这里就不写了,配置资料比较多。这里就是让cpp文件在c++下编译。最后,编程成功,点亮!

yuhu0012的博客 2640

POJ 2492

A Bug's Life Time Limit:10000MS Memory Limit:65536K Total Submissions:16957 Accepted:5446 Description BackgroundProfessor Hopper is researching the sexual ...

weixin_33991418的博客 249

【YOLO系列】YOLOv11详解:模型结构、损失函数、训练方法及代码实现

YOLOv11在目标检测领域实现重大突破,通过动态骨干网络(Dyna-Backbone)和FPN++架构,在保持高帧率(≥60FPS)的同时提升小目标检测精度(AP_S提升5.6%)。创新采用CIoU++损失函数和类别平衡Focal Loss,结合Mosaic-Plus数据增强,参数量减少18%至6.5M。实验显示,该模型在COCO数据集上实现更高mAP,特别适合移动端部署,Jetson Xavier平台能耗比优化至3.2W·ms⁻¹,支持目标检测、实例分割等多任务场景。关键创新包括动态深度调整和双向特征金

一碗白开水一 3458

Apollo Planning决策规划算法代码详细解析 (2):Scenario执行

上一章节讲Scenario的决策逻辑,当确认当前Scenario后,本章节继续深入讲解在代码中,Scenario的执行过程。Scenario的Process()函数根据配置文件顺序执行stage,并判断目前处于哪个stage。当确认好stage后调用该stage对应的Process()函数,来进行具体的规划任务。 码字不易,喜欢的朋友们麻烦点个关注与赞。 在本文你将学到下面这些内容: Scenario的Process()函数的作用于调用方式; Scenario对象的初始化方法; 如何给每个Scen

自动驾驶Player的博客 5612

POJ-2492 A Bug's Life

POJ-2492 A Bug’s Life 题目链接:POJ-2492 题目大意:昆虫有两种性别,如果A与B相爱,则他们异性,B与C相爱,则他们异性,C与A相爱???这就是一个bug,题目要求看提供样例有没有bug 解题思路:思路与POJ的食物链一致>>食物链 代码块: #include<iostream> #include<cstdio> using nam...

鱼头的水题之路 252

AI Agent开发第82课-手把手教你把paddleocr-vl做成mcp使其在DIFY里运行

本文详解如何将国产顶尖多模态 OCR 模型 PaddleOCR-VL 封装为标准 MCP(Model Calling Protocol)服务,并通过自研的 HTTP-based MCP Client 接入 Dify 1.10,实现 AI Agent 在对话中自动识别并调用 OCR 能力。该方案已在某头部保险公司真实业务流程中落地,使用了当前最先进的“Agentic AI 原生”设计思想。

打造全国最全的AI Agent开发知识领域的博客 1634

POJ A Bug's Life

Language: Default A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 29737   Accepted: 9729 Description Background  Professor Hopper is resea

走一步再走一步 1606

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

寒假私训——并查集 D - E - A Bug's Life(进阶)

题目要求 Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite ...

atnanajiang的博客 359

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

POJ 2492 A Bug's Life

A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 24204   Accepted: 7872 Description Background  Professor Hopper is researching the sexual be

ACM2272902662的专栏 1062

老版QQ原生表情gif动态

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

并查集 A Bug's Life

A. A Bug's Life Time Limit: 4000 ms   Case Time Limit: 4000 ms   Memory Limit: 64 MB Total Submission: 30   Submission Accepted: 17 Description Background Professor Hopper is researching the s

zxlove 566

hdu 1892 A Bug's Life

http://acm.split.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14269    Accepted

bushadid的博客 419
上一篇: Wireless Network
下一篇: Supermarket
Techay
博客等级 码龄12年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值