Uva-1160-X-Plosives
来源:互联网 发布:学美容知乎 编辑:程序博客网 时间:2024/04/30 11:43
比较简单的一道并查集练习题
代码:
#include<cstdio>#include<cstring>#include<iostream>#define MAX 100001using namespace std;int p[MAX],ans;int find(int x){ if(p[x]==x)return x; return p[x]=find(p[x]);}int main(){ int a,b; while(scanf("%d",&a)!=EOF) { for(int i=0;i<MAX;i++) p[i]=i;ans=0;while(1){ scanf("%d",&b); int ita=find(a); int itb=find(b); if(ita==itb)ans++; elsep[ita]=itb; scanf("%d",&a); if(a==-1)break;}printf("%d\n",ans); } return 0;}
- 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
- 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 (并查集)
- UVa 1160 X-Plosives(并查集)
- uva 1160 X-Plosives (并查集)
- UVA 1160 - X-Plosives(并查集)
- uva 1160 - X-Plosives(并查集)
- C++ vector 用法汇总
- C# WinForm程序退出的方法
- hibernate4和hibernate3的区别
- 算法设计--串匹配问题:BF算法、KMP算法、BM算法
- Windows的批处理基本应用
- Uva-1160-X-Plosives
- 《第二章 C语言的基本元素》学后感
- 《娃娃遇到兵》bug记录
- 第一次程序设计上机报告
- eclipse快捷键
- VC从文件中加载图片
- java 多线程火车票售票实例
- 地球坐标系 (WGS-84) 到火星坐标系 (GCJ-02) 的转换算法
- POJ 1088 滑雪