【并查集 偏移量】HDU 1829 A Bug's Life
来源:互联网 发布:网络骂人的歌曲最火的 编辑:程序博客网 时间:2024/06/06 02:22
HDU 1829 A Bug's Life
#include <iostream>#include <string>#include <algorithm>#include <math.h>#include <stdio.h>#include <cstring>#include <stdlib.h>using namespace std;int father[100001], rankk[100001], flag, n;int get_fa(int x){ if(x != father[x]) { int t; t = get_fa(father[x]); rankk[x]=(rankk[x]+rankk[father[x]])%2; father[x] = t; return t; } return father[x];}void merge(int a, int b){ int fa, fb; fa = get_fa(a), fb = get_fa(b); if(fa == fb) { if(rankk[a] == rankk[b]) flag = 0; } else { father[fa] = fb; rankk[fa] = (rankk[a] + rankk[b] + 1) % 2; }}int main(){ int T,m,i,a,b,t; scanf("%d",&T); for(t=1; t<=T; ++t) { scanf("%d%d",&n,&m); flag=1; memset(rankk,0,sizeof(rankk)); for(i=1; i<=n; ++i) father[i]=i; while(m--) { scanf("%d%d",&a,&b); if(!flag) continue; merge(a,b); } printf("Scenario #%d:\n",t); if(flag) printf("No suspicious bugs found!\n\n"); else printf("Suspicious bugs found!\n\n"); } return 0;}
0 0
- 【并查集 偏移量】HDU 1829 A Bug's Life
- HDU 1829 A Bug‘s Life 带权并查集&&带偏移量的写法
- Hdu 1829 A Bug's Life && Poj 1182 食物链 (并查集偏移量的应用)
- HDU 1829 A Bug's Life 并查集 + 向量偏移
- hdu 1829 A Bug's Life(并查集+偏移向量)
- POJ 2492 A Bug's Life(种类并查集 + 偏移量)
- 【带偏移量的并查集】:poj2492,A Bug's Life
- 并查集Hdu 1829 A Bug's Life
- HDU 1829 A Bug's Life 并查集
- hdu 1829 A Bug's Life(并查集)
- HDU 1829 A Bug's Life(并查集)
- HDU 1829 A Bug's Life(种类并查集)
- hdu 1829 A Bug's Life (基础并查集)
- HDU 1829 A Bug's Life 并查集
- hdu 1829 A Bug's Life 并查集
- HDU 1829 A Bug's Life (并查集)
- hdu 1829 A Bug's Life 并查集
- hdu 1829 A Bug's Life ( 并查集 )
- 二叉树
- 发帖测试2.3
- UVa 11178 Morley's Theorem(几何)
- Python快速学习08:模块的操作
- Cache的设计和实现 LRU Cache
- 【并查集 偏移量】HDU 1829 A Bug's Life
- sublime利用ClosureCompiler和YUICompressor本地压缩
- 关于ubuntu卸载ibus后导致系统设置不能打开
- 山东省第二届ACM大学生程序设计竞赛(原题) D:Binomial Coeffcients
- com初始化
- 斐波那契数列的递归和非递归算法
- c++继承中的内存布局
- UVa 10820 Send a Table(欧拉函数)
- Android动画之Interpolator和AnimationSet(三)