poj 2492 A Bug's Life(种类并查集)
来源:互联网 发布:知乎 前苏联军事强大 编辑:程序博客网 时间:2024/05/17 08:46
要求根据M对交配关系找出N个虫子中是否存在同性恋/...
和上题一样...T_T
/*Problem ID:I - A Bug's Lifemeaning: 寻找同性恋Analyzing:种类并查集,bug:1,2;1,2.。。T_T*/#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<vector>using namespace std;typedef struct even{int pi,di;}even;#define FOR(i,s,t) for(int i=(s); i<(t); i++)#define BUG puts("here!!!")#define print(x) printf("%d\n",x)#define LL long long#define maxn 2005int pre[maxn],rela[maxn];void init(){ FOR(i,0,maxn){pre[i]=-1;rela[i]=0;}}int find(int x){ int s=x; if(pre[x]<0) return x; s=find(pre[x]); rela[x]=rela[x]^rela[pre[x]]; return pre[x]=s;}void Union (int R1,int R2){ int r1=find(R1); int r2=find(R2); if(r1==r2) return; pre[r1]=r2; rela[r1]=~(rela[R1]^rela[R2]);}int main(){ int T,N,M; int a,b,flag,Cas=1; scanf("%d",&T); while(T--){ flag=1; init(); scanf("%d%d",&N,&M); while(M--){ scanf("%d%d",&a,&b); if(!flag) continue; if(find(a)==find(b)){ if(rela[a]==rela[b]) flag=0; } else Union(a,b); } printf("Scenario #%d:\n",Cas++); if(!flag) printf("Suspicious bugs found!\n"); else printf("No suspicious bugs found!\n"); puts(""); } return 0;}
- poj 2492 A Bug's Life(种类并查集)
- 【种类并查集】-POJ-2492-A bug's life
- Hdu 1892&&Poj 2492 A Bug's Life[判断二分图 || 种类并查集]
- HDU 1829 && POJ 2492 A Bug's Life(种类并查集)
- POJ 2492 A Bug's Life(种类并查集 + 偏移量)
- POJ - 2492 A Bug's Life(种类并查集)
- A Bug's Life(hdu1829种类并查集)
- HDU 1829 A Bug's Life(种类并查集)
- A Bug's Life 种类并查集
- poj2492 A Bug's Life 种类并查集
- A Bug's Life --- 种类并查集
- hdoj-1289-A Bug's Life【种类并查集】
- HDU 1829 A Bug's Life【种类并查集】
- HDU1829:A Bug's Life(种类并查集)
- HDU1829 A Bug's Life(种类并查集)
- 【种类并查集】 hdu1829 A bug's Life
- A Bug's Life(种类并查集)
- POJ2492 -A Bug's Life(种类并查集)
- 远古的徘徊
- java调用c dll,指针参数和结构体参数搞定
- 嫣然一笑苦了情
- MFC打造Java环境变量设置工具...
- JQuery制作可以编辑table
- poj 2492 A Bug's Life(种类并查集)
- HEVC中的TZSearch过程
- Git入门教程
- iPhone开发初步
- Posix多线程-基础
- 黑马程序员——交通灯管理系统学习笔记
- Spring整合Hibernate图文步骤
- VC中鼠标经过按钮弹出功能提示(TIPS)
- 何谓一维表、二维表