这个题目很有意思啊,有一些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. log4Net配置详解

    <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSe ...

  2. 如何利用C#编写网页投票器程序 如何使用代理来投票 代理IP来投票

      一.前言看个图,了解下投票的过程.提交投票信息投票页 ――――――――>投票信息处理页反馈投票结果(请求页)<―――――――(响应页)一般情况下,填写投票信息,然后点提交按钮发送到响应 ...

  3. iOS RC4加解密算法

    -(NSString *)encrypt:(NSString *)string withKey:(NSString *)key{ self.sBox = [[self frameSBox:key] m ...

  4. 【转】Entity Framework教程

    转自:http://www.cnblogs.com/xray2005/category/189491.html   Entity Framework系列文章导航 摘要: 本节集合了Entity Fra ...

  5. SGU 158.Commuter Train

    一道简单题. 火车停的位置不是在整点就是在二分之一点,坐标*2,然后枚举火车停的位置,计算总距离即可. code: #include <iostream> #include <cma ...

  6. seaJs初体验

    目录结构 模块定义define define(function(require,exports,module){ //exports可以把方法或属性暴露给外部 exports.name = 'hell ...

  7. How far away ?

    #include<iostream> #include <algorithm> using namespace std; const int M=40010; int dis[ ...

  8. java.io.serializable

    为什么要实现 java.io.serializable? 简单点:“好处就是将来项目如果要做集群的话,就实现java.io.serializable接口”

  9. jQuery在on绑定事件时,使用Function.prototype.bind上下文,只能用off(event)解绑函数,否则可能导致事件叠加

    因为一个bind函数,未解绑成功导致事件叠加,搞了一下午. keyup事件绑定: this.$document.on('keyup', this.keyUp.bind(this)); 原解绑函数: t ...

  10. QLabel

    The QLabel widget provides a text or image display. Content  Setting Plain text  Pass a QString to s ...