UVA 1160 X-Plosives(并查集)
来源:互联网 发布:淘宝客微信群拉人好难 编辑:程序博客网 时间:2024/05/30 12:30
可以把一个化合物看成一条边,那么两端点就是化合物的两个元素,如果k个化合物,k个元素,那么代表这k条边练成了一个环,所以用并查集来判断就可以了。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define rep(i,a,b) for(int i=(a);i<=(b);i++)#define ss(x) scanf("%d",&x)const int maxn=100000;int fa[maxn];int getroot(int x) {return fa[x]==x?x:fa[x]=getroot(fa[x]);}int main(){ int x,y; while(ss(x)!=EOF) { rep(i,1,maxn) fa[i]=i; int refuse=0; while(true) { if(x==-1) break; ss(y); x=getroot(x);y=getroot(y); if(x==y) refuse++; else fa[y]=x; ss(x); } cout<<refuse<<endl; } return 0;}
0 0
- UVa 1160 X-Plosives (并查集)
- UVa 1160 X-Plosives(并查集)
- uva 1160 X-Plosives (并查集)
- UVA 1160 - X-Plosives(并查集)
- uva 1160 - X-Plosives(并查集)
- UVA 1160X-Plosives【并查集】
- UVA 1160 X-Plosives(并查集)
- X-Plosives - UVa 并查集
- Uva 1160 X-Plosives ——并查集
- uva 1160 - X-Plosives(并查集)
- uva 1160 - X-Plosives(并查集)
- UVA 1160 X-Plosives(并查集)
- uva 1160 X-Plosives(并查集:基础运用)
- UVA 1160 - X-Plosives(并查集)
- UVA 1160 - X-Plosives 即LA3644 并查集判断是否存在环
- UVA 1160 - X-Plosives 并查集判断是否存在环
- LA 3644 - X-Plosives,并查集
- LA 3644 X-Plosives / 并查集
- C++中的static关键字的总结
- NYOJ-456-邮票分你一半(01背包)
- iOS开发自定义UIPickView
- taiga安装手册
- C#日期时间格式化
- UVA 1160 X-Plosives(并查集)
- 隐藏驱动模块
- Java 集合集
- 电容的去耦半径
- 关于CPU affinity的几篇文章
- HDU 5922 Minimum’s Revenge 【模拟】(2016CCPC东北地区大学生程序设计竞赛)
- Quartus 调用PLL IP核仿真
- Unity检测PC连接的网络状态是有线还是无线,无线的强速,速率等
- STM32F101xxT6中VBAT 管脚上的怪现象