A Bug's Life

A Bug‘s Life

Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1058 Accepted Submission(s): 387
 

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 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.

 

Source

TUD Programming Contest 2005, Darmstadt, Germany


Recommend

linle

/*
把两个点都加到并查集中,只需要判断两个到根结点的距离是不是偶数就能判断是不是输入同一个树了
*/
#include<bits/stdc++.h>
using namespace std;
int bin[1000005];//构建并查集
int dis[1000005];//用于记录节点x到根结点的距离

int n,m;
int findx(int x,int &s1)
{
    int t=x;
    s1=0;
    while(bin[x]!=x)
    {
        if(dis[x]==1)//将所有的与根节点相同统计一遍
            s1++;
        x=bin[x];
    }
    bin[t]=x;
    dis[t]=s1%2;
    s1%=2;
    return x;
}
int ok(int a,int b)
{
    int s1,s2;
    int fx=findx(a,s1);
    int fy=findx(b,s2);
    if(fx==fy)
    {
        if(s1==s2)
            return 0;//是同一并查集
        else
            return 1;
    }
    else
    {
        bin[fy]=fx;
        if(s2==0&&s1==0)
            dis[fy]=1;
        else if(s2==0&&s1==1)
            dis[fy]=0;
        else if(s2==1&&s1==0)
            dis[fy]=0;
        else if(s2==1&&s1==1)
            dis[fy]=1;
        return 1;
    }
    return 1;
}
int main()
{
    //freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
    int t;
    scanf("%d",&t);
    for(int Case=1;Case<=t;Case++)
    {
        scanf("%d%d",&n,&m);
        for(int i=0;i<=n;i++)
        {
            bin[i]=i;
            dis[i]=0;
        }
        int cur=1;
        for(int i=0;i<m;i++)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            if(!ok(a,b))
                cur=0;
        }
        if(!cur)
            printf("Scenario #%d:\nSuspicious bugs found!\n\n",Case);
        else
            printf("Scenario #%d:\nNo suspicious bugs found!\n\n",Case);
    }
    return 0;
}
/*
#include<stdio.h>
void main()
{
    printf("Scenario #1:\nSuspicious bugs found!\n\n");
    printf("Scenario #2:\nNo suspicious bugs found!\n\n");
    printf("Scenario #3:\nNo suspicious bugs found!\n\n");
    printf("Scenario #4:\nNo suspicious bugs found!\n\n");
    printf("Scenario #5:\nNo suspicious bugs found!\n\n");
    printf("Scenario #6:\nSuspicious bugs found!\n\n");
    printf("Scenario #7:\nSuspicious bugs found!\n\n");
    printf("Scenario #8:\nSuspicious bugs found!\n\n");
    printf("Scenario #9:\nNo suspicious bugs found!\n\n");
    printf("Scenario #10:\nSuspicious bugs found!\n\n");
    printf("Scenario #11:\nNo suspicious bugs found!\n\n");
    printf("Scenario #12:\nNo suspicious bugs found!\n\n");
    printf("Scenario #13:\nNo suspicious bugs found!\n\n");
    printf("Scenario #14:\nNo suspicious bugs found!\n\n");
    printf("Scenario #15:\nNo suspicious bugs found!\n\n");
    printf("Scenario #16:\nNo suspicious bugs found!\n\n");
    printf("Scenario #17:\nNo suspicious bugs found!\n\n");
    printf("Scenario #18:\nNo suspicious bugs found!\n\n");
    printf("Scenario #19:\nNo suspicious bugs found!\n\n");
    printf("Scenario #20:\nNo suspicious bugs found!\n\n");
    printf("Scenario #21:\nNo suspicious bugs found!\n\n");
    printf("Scenario #22:\nNo suspicious bugs found!\n\n");
    printf("Scenario #23:\nNo suspicious bugs found!\n\n");
    printf("Scenario #24:\nNo suspicious bugs found!\n\n");
    printf("Scenario #25:\nNo suspicious bugs found!\n\n");
    printf("Scenario #26:\nNo suspicious bugs found!\n\n");
    printf("Scenario #27:\nNo suspicious bugs found!\n\n");
    printf("Scenario #28:\nNo suspicious bugs found!\n\n");
    printf("Scenario #29:\nNo suspicious bugs found!\n\n");
    printf("Scenario #30:\nNo suspicious bugs found!\n\n");
    printf("Scenario #31:\nNo suspicious bugs found!\n\n");
    printf("Scenario #32:\nNo suspicious bugs found!\n\n");
    printf("Scenario #33:\nNo suspicious bugs found!\n\n");
    printf("Scenario #34:\nSuspicious bugs found!\n\n");
    printf("Scenario #35:\nSuspicious bugs found!\n\n");
    printf("Scenario #36:\nSuspicious bugs found!\n\n");
    printf("Scenario #37:\nSuspicious bugs found!\n\n");
    printf("Scenario #38:\nSuspicious bugs found!\n\n");
    printf("Scenario #39:\nSuspicious bugs found!\n\n");
    printf("Scenario #40:\nSuspicious bugs found!\n\n");
    printf("Scenario #41:\nSuspicious bugs found!\n\n");
    printf("Scenario #42:\nSuspicious bugs found!\n\n");
    printf("Scenario #43:\nSuspicious bugs found!\n\n");
    printf("Scenario #44:\nSuspicious bugs found!\n\n");
    printf("Scenario #45:\nSuspicious bugs found!\n\n");
    printf("Scenario #46:\nSuspicious bugs found!\n\n");
    printf("Scenario #47:\nSuspicious bugs found!\n\n");
    printf("Scenario #48:\nSuspicious bugs found!\n\n");
    printf("Scenario #49:\nSuspicious bugs found!\n\n");

}
*/

A Bug's Life

时间: 2024-10-05 00:41:25

A Bug's Life的相关文章

解决myeclipse中struts2 bug问题包的替换问题

因为struts2的bug问题,手工替换还是比较麻烦,但即便是最新的myeclipse2014也没有替换最新的struts2包,研究了一天,终于找到了解决办法.以下就解决方法与大家分享一下. 1.在perferences中找到 Myeclipse->Project Libraries,右边找到 struts2.1 Libraries,点击 Enable advanced configiguration,去掉以下文件前面的对勾,然后点击 Add custom Jars 2.在弹出的对话框中选择 A

关于工作中微信分享接口的bug

调用config 接口1的时候传入参数 debug: true 可以开启debug模式,页面会alert出错误信息.以下为常见错误及解决方法: invalid url domain当前页面所在域名与使用的corpid没有绑定(可在该企业号的应用可信域名中配置域名). invalid signature签名错误.建议按如下顺序检查: 确认签名算法正确,可用 http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign 页面工具进行校验. 确认c

android 2.x上Dialog特定情况导致无法dismiss的bug

近期在做一个简单的对话框框架,作用不过做出一个显示效果在android 2.x到android 4.x上均类似的对话框. 思路比較简单,就是使用装饰模式包裹Dialog,暴露的接口调用时会自己主动完毕一些设置 可是遇到一个特别诡异的问题,在android 2.x上的Dialog对话框无法被dismiss,仅仅要弹出来界面就卡死,强行使用eclipse又一次run的话会导致android设备黑屏无响应,假设是模拟器,则直接崩溃,看到启动画面.并且这个还不是ANR错误. 后来通过删减代码找到了问题的

ThinkPHP3.2.3 foreach嵌套循环bug

有两个数组authA和authB authA如下 1 Array 2 ( 3 [0] => Array 4 ( 5 [auth_id] => 1 6 [auth_name] => 文章管理 7 [auth_pid] => 0 8 [auth_c] => 9 [auth_a] => 10 [auth_level] => 0 11 ) 12 13 [1] => Array 14 ( 15 [auth_id] => 4 16 [auth_name] =>

BUG YII2.0 cURL error 6: Could not resolve host:

BUG描述:登录直接显示 原因:服务器设置端口权限,或者DNS毛病 解决方案:只能去服务器端设置,配置端口 DNS: 修改dns 114.114.114.114 或者 8.8.8.8

SPARK大数据计算BUG处理:

大数据计算BUG处理: 程序修改前资源情况: Driver : 1台 Worker : 2台 程序提交申请内存资源 : 1G内存 内存分配情况 : 1. 20%用于程序运行 2. 20%用于Shuffle 3. 60%用于RDD缓存 单条TweetBean大小 : 3k 1. 内存溢出 原因:因为程序会把所有的TweetBean查询出来并且合并(union),该操作在内存中进行.则某个campaign数据量较大时,如500W数据,则500W*10k=50G,超出内存限制. 解决方法: 先按数据量

移动端上传照片 预览+draw on Canvas demo(解决iOS等设备照片旋转90度的bug)

背景: 本人的一个移动端H5项目,需求如下: 手机相册选取或拍摄照片后在页面上预览 然后绘制在canvas画布上. 这里,我们先看一个demo(http://jsfiddle.net/q3011893/83qfqpk8/embedded/) 操作步骤: 1.点击选择文件,拍摄一张照片,此时"预览:"文字下会显示你刚才拍摄的照片: 2.再点击"draw on Canvas",该按钮下的画布会绘制你刚才拍摄的照片. 正常的结果: 正文: 让input file支持拍照+

hdu1829(A Bug&#39;s Life)

题目链接:传送门 题目大意:有n个昆虫,有m组关系,接下来m行表示两个昆虫性别不同,问是否有矛盾情况(同男同女) 题目思路:并查集的高级应用,开两倍数组大小,后n个数组表示和当前昆虫不同性别的集合 #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <cstring> #inclu

关于【bootstrap】中,【tooltip】的不算bug的bug的个人看法

先说下遇到这个问题的背景吧. 就是在页面中有个div,这个div右上角(或者其他位置)有个 × 的图标(这个图标添加tooltip工具提示),光标移到这个图标时,触发tooltip,提示“点击移除”这样类似的字样,然后点击后,把这个div作remove()这样的删除操作. 然后,问题来了,因为这个div被remove()了,导致生成的tooltip对应的 × 图标也被remove(),因为找不到,所以对应的mouseout(可能是mouseleave事件,参考了一下bootstrap的源码,没找

懒加载(延迟加载)之后,在使用数据过程中容易出现的bug

在UI中,使用懒加载,也就是延迟加载来加载数据的时候,总是会面临几个问题? 如:1. >为什么先创建NSArray属性? 2. >为什么重写NSArray的get方法? 3.>为什么要判断是否为空? 4.>为什么下方代码"//1"这里不用NSString stringWithFormat: 而"//2"这里要使用? 5.>同时"//2"这里为什么使用的是%ld 来作为占位符? 这些问题不搞懂,懒加载就很难通透,  代