poj2524Ubiquitous Religions
来源:互联网 发布:java list泛型 遍历 编辑:程序博客网 时间:2024/06/05 05:48
http://poj.org/problem?id=2524
并查集的基本操作,路径压缩等
<span style="font-size:18px;">#include <stdio.h>int parent[50005],count;/*思想:每次查找的时候,如果路径较长,则修改信息,以便下次查找的时候速度更快*/int find (int x)//带路径压缩的查找算法{ int r;for (r = x; parent[r] != r; r = parent[r]); //循环结束,则找到根节点while ( x != r ) //修改查找路径上的所有节点,将它们都指向根结点{int s = parent[x];parent[x] = r;x = s;}return r;}int unite(int x,int y){int u,v; u=find(x); v=find(y); if(u!=v) { parent[u]=v; count--; }}int main(){int n,m,x,i,j,c=1;while(scanf("%d %d",&n,&m)!=EOF){ count=n;if(n==0&&m==0)break;for(x=1;x<=n;x++)parent[x]=x; for(x=1;x<=m;x++) { scanf("%d %d",&i,&j); unite(i,j);}printf("Case %d: %d\n",c++,count);}return 0;}</span>
0 0
- poj2524Ubiquitous Religions
- POJ2524Ubiquitous Religions
- poj2524Ubiquitous religions…
- POJ2524Ubiquitous Religions(并查集)
- POJ2524Ubiquitous Religions(并查集)
- POJ2524Ubiquitous Religions [数据结构-并查集 union-find sets]
- BIT1061Ubiquitous Religions
- Ubiquitous Religions
- poj_2524Ubiquitous Religions
- Ubiquitous Religions
- Ubiquitous Religions
- Ubiquitous Religions
- Ubiquitous Religions
- Ubiquitous Religions
- Ubiquitous Religions
- Ubiquitous Religions
- Ubiquitous Religions
- Ubiquitous Religions
- android ViewPager嵌套的使用方法
- Spark 定制版:009~Spark Streaming源码解读之Receiver在Driver的精妙实现全生命周期彻底研究和思考
- java数据结构之单链表
- ThreadLocal介绍
- R语言预处理之异常值问题
- poj2524Ubiquitous Religions
- Canvas和SVG
- cocoaPods
- 拦截malloc、free等库函数(malloc钩子)
- 应用沙盒分析
- geekband android #5 第十三周分享(Btimap优化)
- 九九乘法表的C语言实现
- 三种常见排序
- 利用函数调用,对数组进行初始化,更改,清零,逆置等操作