这个题目很有意思啊,有一些bug生物(肯定是程序员养的),有人观察他们的生活习惯,观察他们之间是否有同性恋关系,比如ab发生关系,bc发生关系,ab发生关系。。。产生了同性恋了,你需要判断一下这种关系是不是存在。
分析,这个跟食物链没什么区别,而且条件还少了不少,规定同性关系是0, 异性关系是1
//////////////////////////////////////////////////////////////////////

#include <stdio.h>

#include<algorithm>
using namespace std; const int maxn = ; int f[maxn], relation[maxn];//0表示同性,1表示异性 int Find(int x)
{
    int k = f[x];
    if(f[x] != x)
    {
        f[x] = Find(f[x]);
        relation[x] = (relation[x]+relation[k])%;
    }     return f[x];
} int main()
{
    int T, t=;     scanf("%d", &T);     while(T--)
    {
        int i, N, M, u, v, ru, rv, ok = ;         scanf("%d%d", &N, &M);         for(i=; i<=N; i++)
            f[i] = i, relation[i] = ;         for(i=; i<M; i++)
        {
            scanf("%d%d", &u, &v);             if(ok)continue;             ru = Find(u), rv = Find(v);             if(ru == rv && (relation[v]+)% != relation[u])
                ok = ;
            else if(ru != rv)
            {
                f[ru] = rv;
                relation[ru] = (-relation[u]+relation[v])%;
            }
        }         if(t != )printf("\n");
        printf("Scenario #%d:\n", t++);
        if(ok)printf("Suspicious bugs found!\n");
        else printf("No suspicious bugs found!\n");
    }     return ; }

J - A Bug's Life - poj2492的更多相关文章

  1. J - A Bug's Life 并查集

    Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...

  2. A Bug's Life - poj2492

    Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Descr ...

  3. poj1483 It's not a Bug, It's a Feature!

    It's not a Bug, It's a Feature! Time Limit: 5000MS   Memory Limit: 30000K Total Submissions: 1231   ...

  4. 【POJ】2096 Collecting Bugs

    http://poj.org/problem?id=2096 题意:s个系统n种bug,每天找出一个bug,种类的概率是1/n,系统的概率是1/s.问:每个系统至少找出一个bug:每种类的bug都被找 ...

  5. ACM - 概率、期望题目 小结(临时)

    概率DP求期望大多数都是全期望公式的运用.主要思考状态空间的划分以及状态事件发生的概率.问题可以分为无环和有环两类.无环一类多数比较简单,可以通过迭代或者记忆化搜索完成.有环一类略复杂,可以通过假设方 ...

  6. 【POJ】【2096】Collecting Bugs

    概率DP/数学期望 kuangbin总结中的第二题 大概题意:有n个子系统,s种bug,每次找出一个bug,这个bug属于第 i 个子系统的概率为1/n,是第 j 种bug的概率是1/s,问在每个子系 ...

  7. Rockethon 2015

    A Game题意:A,B各自拥有两堆石子,数目分别为n1, n2,每次至少取1个,最多分别取k1,k2个, A先取,最后谁会赢. 分析:显然每次取一个是最优的,n1 > n2时,先手赢. 代码: ...

  8. hihocoder 1084 扩展KMP && 2014 北京邀请赛 Justice String

    hihocoder 1084 : http://hihocoder.com/problemset/problem/1084 北京邀请赛 Just  String http://www.bnuoj.co ...

  9. CodeChef November Challenge 2014

    重点回忆下我觉得比较有意义的题目吧.水题就只贴代码了. Distinct Characters Subsequence 水. 代码: #include <cstdio> #include ...

随机推荐

  1. reflact中GetMethod方法的使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  2. SQL SERVER 存储过程基础

    一.注释 -- 单行注释,从这到本行结束为注释,类似C++,c#中// /* … */ 多行注释,类似C++,C#中/* … */ 二.变量 (int, smallint, tinyint, deci ...

  3. Jquery 点击空白处消失

    $(document).bind("click", function (e){ if ( $((e.target || e.srcElement)).closest("# ...

  4. JDK常用类_util

    集合 Collection:集合顶层接口 AbstractCollection:集合抽象类 关联数组 Map:顶层接口 AbstractMap:抽象类实现,提供了子类的通用操作 HashMap:哈希表 ...

  5. 【POJ3580】【splay版】SuperMemo

    Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participant i ...

  6. 利用js获取时间并输出值

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  7. Ubuntu phpmyadmin 缺少mcrypt扩展解决方法

    之前在登陆phpmyadmin的时候,会出现警告说缺少mcrypt扩展的错误,一直没去解决这个问题,觉得没什么影响就算了. 今天谷歌了一下,原来是php5没有启用mcrypt模块.   sudo ph ...

  8. iOS 的 XMPPFramework 简介一

    XMPPFramework是一个OS X/iOS平台的开源项目,使用Objective-C实现了XMPP协议(RFC-3920),同时还提供了用于读写XML的工具,大大简化了基于XMPP的通信应用的开 ...

  9. 在iOS7中修改状态栏字体的颜色-b

    状态栏的字体为黑色: UIStatusBarStyleDefault 状态栏的字体为白色: UIStatusBarStyleLightContent 一.在 info.plist  中,将 View ...

  10. HTML中如何添加日历插件(JQUERY)

    日期插件的包为:mydate.js1:首先将日期插件的包引入到页面中 1 <script language="JavaScript" src="../Inc/Js/ ...