UVA 1329 - Corporative Network(带权并查集)
来源:互联网 发布:网络黑客攻击 编辑:程序博客网 时间:2024/05/22 23:06
UVA 1329 - Corporative Network
题目链接
题意:有n个结点,开始都是单独的结点,现在有I操作和E操作,I u v表示吧u的父亲结点设为,距离为|u - v| % 1000,E操作询问u到根的距离
思路:带权并查集,就多一个权表示距离即可
代码:
#include <cstdio>#include <cstring>#include <cstdlib>const int N = 20005;int t, n, parent[N], d[N];int find(int x) { if (x == parent[x]) return x; int px = find(parent[x]); d[x] += d[parent[x]]; return parent[x] = px;}int main() { scanf("%d", &t); while (t--) {scanf("%d", &n);for (int i = 0; i <= n; i++) { parent[i] = i; d[i] = 0;}char q[5];int a, b;while (~scanf("%s", q)) { if (q[0] == 'O') break; if (q[0] == 'E') {scanf("%d", &a);find(a);printf("%d\n", d[a]); } if (q[0] == 'I') {scanf("%d%d", &a, &b);int pa = find(a);int pb = find(b);parent[a] = b;d[a] = abs(a - b) % 1000; }} } return 0;}
0 0
- UVa:1329 Corporative Network(带权并查集)
- UVa 1329 Corporative Network(带权并查集)
- UVA 1329 - Corporative Network(带权并查集)
- UVA 1329Corporative Network【并查集】
- UVA 1329 Corporative Network(并查集)
- Corporative Network(带权并查集)
- UVALive - 3027Corporative Network(带权并查集)
- LA3027 Corporative Network 带权并查集入门
- poj 1962 Corporative Network(带权并查集)
- POJ - 1962 Corporative Network(带权并查集)
- UVALive 3027 Corporative Network (带权并查集)
- poj1962 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(并查集)
- c++中的初始化
- JQuery之为某个div添加行样式
- Irony-server 编译的方法
- XMLHTTP中setRequestHeader参数问题
- 概率性的bug比较恼人(软件质量不是一句废话)
- UVA 1329 - Corporative Network(带权并查集)
- Ogre1.7.2 + CEGUI0.7.5配置
- 南阳766 想好久都错,原来可以这样
- 黑马程序员_java基础篇之网络编程
- 进制转换
- Redhat中设置环境变量PATH的方法
- hdoj 1492 The number of divisors(约数) about Humble Numbers 【数论】【质因子分解 求和】
- Linux系统编程(14)——shell常用命令
- BOJ 444. 爱好和平