指南 第三章 例题5 UVALive 3644 X-Plosives(并查集)
来源:互联网 发布:杭州锐智软件 编辑:程序博客网 时间:2024/06/11 04:03
题目链接:http://7xjob4.com1.z0.glb.clouddn.com/eab170e979d9683005d958b058d6ce76
思路:就是加入后成环的元素不可以被加入。
下面是AC代码:
#include<cstdio>const int maxn=100000+10;int pre[maxn];int findset(int x){ if(x==pre[x]) { return x; } else { return pre[x]=findset(pre[x]); }}int main(){ int x,y; while(scanf("%d",&x)==1) { for(int i=0;i<=maxn;i++) { pre[i]=i; } int refusales=0; while(x!=-1) { scanf("%d",&y); x=findset(x); y=findset(y); if(x==y) { ++refusales; } else { pre[x]=y; } scanf("%d",&x); } printf("%d\n",refusales); } return 0;}
0 0
- 指南 第三章 例题5 UVALive 3644 X-Plosives(并查集)
- UVALive 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- UVALive(LA) 3644 X-Plosives (并查集)
- UVALive - 3644X-Plosives(并查集)
- UVALive - 3644 - X-Plosives (并查集!!)
- uvalive 3644 X-Plosives(并查集)
- UVALive 3644 X-Plosives (并查集)
- X-Plosives +uvalive+并查集+水题
- UVALive 3644 X-Plosives(简单并查集)
- 指南 第三章 例题6 UVALive 3027 Corporative Network(并查集的应用)
- 初学并查集的例题1 X-Plosives,LA 3644
- UVALive X-Plosives(并查集+略坑的输入)
- LA 3644 - X-Plosives,并查集
- LA 3644 X-Plosives / 并查集
- LA -3644 X-Plosives -并查集
- LA 3644 X-Plosives 并查集
- Hungarian Algorithm Summary
- 面向对象_长方形案例练习
- 前端生涯即将开始
- 去掉UIButton状态改变时的动画
- 再看Java集合
- 指南 第三章 例题5 UVALive 3644 X-Plosives(并查集)
- 华为面试 手写代码 判断int类型的数是否是回文
- VS2010/MFC编程入门之二十(常用控件:静态文本框)
- 对ViewPagerIndicator的认识
- Redis 如何处理客户端连接
- Android大图片裁剪终极解决方案(上:原理分析)
- Docker入门篇(简介、特性、安装)
- Javascript-正则简单验证身份证号
- trie 树的简单实现