hdu 1829 带权并查集的运用类似于食物链但是更简单些
#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 带权并查集的运用类似于食物链但是更简单些的更多相关文章
- HDU - 3038 带权并查集
这道题我拖了有8个月... 今天放假拉出来研究一下带权的正确性,还有半开半闭的处理还有ab指向的一系列细节问题 #include<iostream> #include<algorit ...
- hdu 3038带权并查集
#include<stdio.h> #include<string.h> #define N 200100 struct node { int x,count; }pre[N ...
- Zjnu Stadium HDU - 3047 带权并查集板子题
#include<iostream> #include<cstring> #include<cstdio> using namespace std; +; int ...
- HDU 1829 A Bug's Life 【带权并查集/补集法/向量法】
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
- hdu 1829 &poj 2492 A Bug's Life(推断二分图、带权并查集)
A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu 5441 Travel 离线带权并查集
Travel Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5441 De ...
- HDU 3047 Zjnu Stadium(带权并查集)
http://acm.hdu.edu.cn/showproblem.php?pid=3047 题意: 给出n个座位,有m次询问,每次a,b,d表示b要在a右边d个位置处,问有几个询问是错误的. 思路: ...
- 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 ...
- 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 ...
随机推荐
- expect安装测试-自动登陆脚本
安装: yum list | grep expect yum install expect 参考:http://www.cnblogs.com/iloveyoucc/archive/2012/05/1 ...
- Google Deepmind AI tries it hand at creating Hearthstone and Magic: The Gathering cards
http://www.techrepublic.com/article/google-deepmind-ai-tries-it-hand-at-creating-hearthstone-magic-t ...
- IJ-Error:常见错误
ylbtech-IJ-Error:常见错误 1.返回顶部 1. This application has no explicit mapping for /error, so you are seei ...
- openStack 主机流量计运行状态 随笔记录
root@ruiy-controller:~# ifconfigeth0 Link encap:Ethernet HWaddr 0c:c4:7a:0d:97:2c ine ...
- 关于form/input 的autocomplete="off"属性
转自:http://blog.sina.com.cn/s/blog_b49f96a701019m0d.html 一. 有过表单设计经验的朋友肯定知道,当我们在浏览器中输入表单信息的时候,往往input ...
- Coursera Algorithms week1 查并集 练习测验:3 Successor with delete
题目原文: Given a set of n integers S = {0,1,…,N-1}and a sequence of requests of the following form: Rem ...
- XML案例(使用JAXP进行DOM解析)
1.book.xml <?xml version="1.0" encoding="UTF-8" standalone="no"?> ...
- Area(pick定理)
http://poj.org/problem?id=1265 题意:起始为(0,0),给出每个点的偏移量,求依次连接这些点形成的多边形边界上格点的个数. 思路:先将各个点的坐标求出存入,由pick定理 ...
- thymeleaf公共页面元素抽取
1.抽取公共片段 使用thymeleaf的th:fragment为样抽取的公共片段命名, 如下把div标签命名为 copy,就可以获取到div整个里的内容<div th:fragment=&qu ...
- TCP/IP详解(三)
超时与重传: TCP在发送一个包时,启动一个定时器,如果在定时器溢出之前没有收到ACK,则认为发出的包丢失了,此时会重传丢失的包.这就是超时重传. 其中定时器的时间不是一个固定值,它是根据RTT计算的 ...