#include<stdio.h>
#define N 1100000
struct node {
int x,y;
}f[N],pre[N];
int find(int x) {
if(x!=pre[x].x) {
int h=pre[x].x;
pre[x].x=find(h);
pre[x].y=(pre[x].y+pre[h].y)%2;
}
return pre[x].x;
}
int main() {
int t,m,n,i,j,k,flag,cou=0;
scanf("%d",&t);
while(t--) {
scanf("%d%d",&n,&m);
for(i=0;i<m;i++)
scanf("%d%d",&f[i].x,&f[i].y);
for(i=1;i<=n;i++) {
pre[i].x=i;
pre[i].y=0;
}
flag=0;
for(i=0;i<m;i++){
j=find(f[i].x);
k=find(f[i].y);
if(j!=k) {
pre[j].x=k;
pre[j].y=(pre[f[i].y].y-pre[f[i].x].y+1)%2;
}
else {
if((pre[f[i].x].y-pre[f[i].y].y)%2==0) {
flag=1;
break;
}
}
}
printf("Scenario #%d:\n",++cou);
if(flag)
printf("Suspicious bugs found!\n\n");
else
printf("No suspicious bugs found!\n\n"); }
return 0;
}

hdu 1829 带权并查集的运用类似于食物链但是更简单些的更多相关文章

  1. HDU - 3038 带权并查集

    这道题我拖了有8个月... 今天放假拉出来研究一下带权的正确性,还有半开半闭的处理还有ab指向的一系列细节问题 #include<iostream> #include<algorit ...

  2. hdu 3038带权并查集

    #include<stdio.h> #include<string.h> #define N  200100 struct node { int x,count; }pre[N ...

  3. Zjnu Stadium HDU - 3047 带权并查集板子题

    #include<iostream> #include<cstring> #include<cstdio> using namespace std; +; int ...

  4. HDU 1829 A Bug's Life 【带权并查集/补集法/向量法】

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

  5. hdu 1829 &amp;poj 2492 A Bug&#39;s Life(推断二分图、带权并查集)

    A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  6. hdu 5441 Travel 离线带权并查集

    Travel Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5441 De ...

  7. HDU 3047 Zjnu Stadium(带权并查集)

    http://acm.hdu.edu.cn/showproblem.php?pid=3047 题意: 给出n个座位,有m次询问,每次a,b,d表示b要在a右边d个位置处,问有几个询问是错误的. 思路: ...

  8. HDU 3038 - How Many Answers Are Wrong - [经典带权并查集]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  9. Valentine's Day Round hdu 5176 The Experience of Love [好题 带权并查集 unsigned long long]

    传送门 The Experience of Love Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

随机推荐

  1. 新手对ASP.NET MVC的疑惑

    习惯了多年的WEB FORM开发方式,突然转向MVC,一下子懵了,晕头转向,好多不习惯,好多不明白,直到现在也没弄明白,只好先记下来,在应用中一一求解. 主要集中在视图(View)这里. 1.@Htm ...

  2. Codeforces--633D--Fibonacci-ish(暴力搜索+去重)(map)

    Fibonacci-ish Time Limit: 3000MS   Memory Limit: 524288KB   64bit IO Format: %I64d & %I64u Submi ...

  3. 在linux查看内存的大小

    用free -m查看的结果: # free -m          total    used    free     shared buffers     cached Mem:           ...

  4. poj2975 Nim(经典博弈)

    Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5866   Accepted: 2777 Description N ...

  5. bzoj 1468 Tree(点分治模板)

    1468: Tree Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1527  Solved: 818[Submit][Status][Discuss] ...

  6. 语法错误1:TabError: Inconsistent use of tabs and spaces in indentation

    如图错误: 出错原因: 由于写代码过程用的tab缩进 解决方法: 把tab缩进改用空格缩进

  7. C#之实体类

    一.为什么要用实体类? |  使程序简洁易懂,便于维护. |  暗合接口不变原则. |  体现面向对象思想.         举例说明: 不用实体类的三层 假如程序有所变动,需要增加一个参数,学生年龄 ...

  8. Last-Modified If-Modified-Since ETag If-None-Match

    Last-Modified.If-Modified-Since 有些数据随时都在变化. CNN.com 的主页经常几分钟就更新.另一方面,Google.com 的主页几个星期才更新一次 (当他们上传特 ...

  9. 一张图说明DIV盒子距离

    虚线的宽高为你实际指定的width和height 虚线外的白色区域为padding 红色区域为border的width 红色外的区域为margin

  10. [原创]Linux(CentOS)下安装nodejs+express

    网上找了很多步骤,各种问题,自己总结下吧 1.下载 wget --no-check-certificate https://nodejs.org/dist/v6.10.1/node-v6.10.1-l ...