uva 1329 - Corporative Network(数据结构:并查集)
来源:互联网 发布:搜狗皮肤编辑器mac 编辑:程序博客网 时间:2024/05/18 12:03
并查集的简单运用
在使用并查集的过程中维护当前点到根的距离
代码如下:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAXN 20100using namespace std;int dis[MAXN], p[MAXN];int findset(int x) { if(p[x] == x) return x; else { int root = findset(p[x]);//在这个过程中求出了p[x]到根的距离dis[p[x]] dis[x] += dis[p[x]]; return p[x] = root; }}int main(void) { int T, N, c, d, i; char ch; cin >> T; while(T--) { cin >> N; for(i=0; i<N; ++i) { dis[i] = 0; p[i] = i; } while(true) { getchar(); ch = getchar(); if(ch == 'E') { cin >> c; findset(c); cout << dis[c] << endl; } else if(ch == 'I'){ cin >> c >> d; p[c] = d; dis[c] = abs(c-d)%1000; } else if(ch == 'O') break; } } return 0;}
0 0
- uva 1329 - Corporative Network(数据结构:并查集)
- UVA 1329Corporative Network【并查集】
- UVA 1329 Corporative Network(并查集)
- UVa 1329 Corporative Network (加权并查集)
- UVA 1329 Corporative Network(并查集:路径压缩)
- UVa:1329 Corporative Network(带权并查集)
- UVa 1329 Corporative Network(带权并查集)
- UVA 1329 - Corporative Network(带权并查集)
- uva 1329 - Corporative Network(加权并查集)
- UVA - 1329 Corporative Network 合作网络(并查集)
- UVa 1329 Corporative Network(并查集)
- LA3027:Corporative Network(并查集) uva 1329
- UVA 1329 Corporative Network——加权并查集
- 1329 - Corporative Network(并查集)
- POJ1962 Corporative Network 并查集
- LA3027 - Corporative Network,并查集
- LA 3027 Corporative Network / 并查集
- Corporative Network +uvalive+并查集
- freemaker中配置文件freemarker.properties详解
- Linux--根文件系统的挂载过程分析
- Android的内存管理机制
- Oracle导出当前用户下所有表的表注释,字段 字段注释
- Java对称与非对称加密解密,AES与RSA
- uva 1329 - Corporative Network(数据结构:并查集)
- 杭电1253 胜利大逃亡
- MySQL 加锁处理分析
- Oracle数据库备份与还原命令
- 【leetcode】Container With Most Water
- c 线程的取消和终止
- 电子商务中的社会化营销逻辑 三个成功案例的启发
- 男子抢劫入狱车辆被扣 3年后出狱被索3万停车费
- expdp备份缓慢问题分析(_2)