HDU_1829 A Bug's Life [ 向量+并查集]
来源:互联网 发布:山东舜德数据怎么样 编辑:程序博客网 时间:2024/06/05 17:45
传送门:HDU 1829
题意:给你一些关系,a b,表示a和b的性别不同,从中找出同性恋的bug。
思路:向量,在并查集中的应用,rel[x] 记录x到root的关系。具体思想参见:Ac_sorry的博客
代码:
#include<iostream>#include<cstdio>using namespace std;int uset[2020];int rel[2020];void make_set(int n){ for(int i=1;i<=n;i++) { uset[i]=i; rel[i]=0; }}int find_set(int x){ if(uset[x]!=x) { int t=uset[x]; uset[x]=find_set(uset[x]); rel[x]=(rel[t]+rel[x])%2; } return uset[x];}int union_set(int x,int y){ int fx=find_set(x),fy=find_set(y); if(fx==fy) { if(rel[x]==rel[y]) return 1; else return 0; } uset[fx]=fy; rel[fx]=(2-rel[x]+1+rel[y])%2; return 0;}int main(){ int n,m; int cas=0; int T; cin>>T; while(T--) { scanf("%d%d",&n,&m); int u,v; int ok=0; make_set(n); for(int i=0;i<m;i++) { scanf("%d%d",&u,&v); if(ok==0) { ok= union_set(u,v); } } printf("Scenario #%d:\n",++cas); if(ok) printf("Suspicious bugs found!\n\n"); else printf("No suspicious bugs found!\n\n"); } return 0;}
0 0
- HDU_1829 A Bug's Life [ 向量+并查集]
- HDU_1829 A Bug's Life(并查集)
- A Bug's Life 并查集
- 并查集 A Bug's Life
- A Bug's Life 并查集
- HDU 1829 A Bug's Life 并查集 + 向量偏移
- poj 2492--A Bug's Life(并查集,向量偏移)
- POJ 2492--A Bug's Life 【并查集,向量偏移】
- hdu 1829 A Bug's Life(并查集+偏移向量)
- 偏移向量并查集——A Bug's Life
- poj 2492 A Bug's Life(并查集)
- 变异并查集2223: A Bug's Life
- POJ 2492 A Bug's Life(并查集)
- poj 2492 并查集 A Bug's Life
- POJ-2492 a bug's life 并查集
- HDU1829 A Bug's Life 并查集
- poj 2492 并查集 a bug's life
- 并查集Hdu 1829 A Bug's Life
- mac os升级Yosemite之后,Versions启动闪退
- 分离出整数的各位数(多种输入形式的处理)
- 第十二周项目3——5 十进制数的二进制形式
- Activemq集群部署API
- const extern static
- HDU_1829 A Bug's Life [ 向量+并查集]
- Visual C#.net 查询windows索引服务目录
- 潜伏鹰:隐蔽通信(FQ)和侦查取证那些事儿(听课总结)
- spm管理
- Unique Paths II
- Android--Service之绑定服务交互
- android service(本地) 知识点
- eclipse编辑jsp文件和javascript代码很卡解决办法
- 同时安装两个nginx