POJ 2492 A Bug's Life 并查集
来源:互联网 发布:it是什么意思 编辑:程序博客网 时间:2024/05/05 12:52
#include <iostream>#include<cstdio>using namespace std;int f[3000],relation[3000];void init(int n){ for(int i=0;i<=n;i++) { f[i]=i; relation[i]=1; }}int find(int x){ if(x==f[x]) return x; int tem=f[x]; f[x]=find(f[x]); relation[x]=(relation[x]+relation[tem]+1)%2; return f[x];}void uni(int a,int b,int x,int y){ f[x]=y; relation[x]=(relation[a]-relation[b])%2;}int main(){ // freopen("cin.txt","r",stdin); int t,n,m,x,y,flag,a,b; scanf("%d",&t); for(int cnt=1;cnt<=t;cnt++) { scanf("%d%d",&n,&m); init(n); flag=0; while(m--) { scanf("%d%d",&x,&y); if(flag) continue; a=find(x),b=find(y); if(a==b&&relation[x]==relation[y]) { flag=1; continue; } uni(x,y,a,b);//错这里了 } printf("Scenario #%d:\n",cnt); if(flag) printf("Suspicious bugs found!\n"); else printf("No suspicious bugs found!\n"); printf("\n"); } return 0;}
0 0
- poj 2492 A Bug's Life(并查集)
- POJ 2492 A Bug's Life(并查集)
- poj 2492 并查集 A Bug's Life
- POJ-2492 a bug's life 并查集
- poj 2492 并查集 a bug's life
- POJ 2492 A Bug's Life (并查集)
- poj 2492 A Bug's Life(种类并查集)
- poj 2492 -- A Bug's Life(并查集)
- POJ 2492 A Bug's Life (并查集)
- poj 2492 - A Bug's Life(并查集)
- 【种类并查集】-POJ-2492-A bug's life
- POJ 2492 A Bug's Life(并查集)
- POJ-2492 A Bug's Life 并查集
- [POJ 2492] A Bug's Life [扩展并查集]
- poj 2492 A Bug's Life 【并查集拓展】
- poj 并查集 - 2492 A Bug's Life
- POJ 2492 A Bug's Life 并查集
- [POJ 2492]A Bug's Life[并查集]
- Ajax+SQL Server无刷新实现图片切换特效
- 数据持久化
- ISP、IAP、ICP烧写方式的区别
- 0.python基本算法
- 计蒜客 难题题库 142 求数组的最长递减子序列
- POJ 2492 A Bug's Life 并查集
- PMP杂谈--项目管理计划
- PHP的Excel文件操作
- LeetCode #200 Number of Islands
- [图] 图论基本介绍
- iOS平台XML解析类库对比和安装说名
- malloc(sizeof(char *)*n)模型
- CoreMotion框架中加速度计使用简明教程
- 计蒜客 难题题库 143 连续正整数