3027 - Corporative Network
3027 - Corporative Network
思路:并查集;
cost记录当前点到根节点的距离,每次合并时路径压缩将cost更新。
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<math.h>
6 #include<stack>
7 #include<set>
8 #include<queue>
9 using namespace std;
10 int bin[20005];
11 int du[20005];
12 char str[20];
13 int main(void)
14 {
15 int i,j;
16 int n;
17 scanf("%d",&n);
18 while(n--)
19 {
20 int m;
21 scanf("%d",&m);
22 for(i = 1; i <= 20005; i++)
23 bin[i] = i,du[i] = 0;
24 while(scanf("%s",str),str[0]!='O')
25 {
26 int x,y;
27 if(str[0]=='I')
28 {
29 scanf("%d %d",&x,&y);
30 int xx;
31 for(xx = y; bin[xx]!=xx;)
32 {
33 xx = bin[xx];
34 du[y]+=du[xx];
35 }
36 bin[y] = xx;
37 bin[x] = xx;
38 du[x] = du[y]+abs(x-y)%1000;
39 }
40 else
41 { int sum = 0;
42 int xx;scanf("%d",&x);
43 for(xx = x; bin[xx]!=xx;)
44 {
45 xx=bin[xx],du[x]+=du[xx];
46 }
47 bin[x] = xx;
48 printf("%d\n",du[x]);
49 }
50 }
51 }
52 return 0;
53 }
3027 - Corporative Network的更多相关文章
- 【暑假】[实用数据结构]UVAlive 3027 Corporative Network
UVAlive 3027 Corporative Network 题目: Corporative Network Time Limit: 3000MS Memory Limit: 30000K ...
- 3027 - Corporative Network(并差集)
3027 - Corporative Network A very big corporation is developing its corporative network. In the begi ...
- UVALive 3027 Corporative Network
---恢复内容开始--- Corporative Network Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld ...
- [LA] 3027 - Corporative Network [并查集]
A very big corporation is developing its corporative network. In the beginning each of the N enterpr ...
- LA 3027 Corporative Network 并查集记录点到根的距离
Corporative Network Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [S ...
- UVALive 3027 Corporative Network 带权并查集
Corporative Network A very big corporation is developing its corporative networ ...
- 并查集 + 路径压缩(经典) UVALive 3027 Corporative Network
Corporative Network Problem's Link Mean: 有n个结点,一开始所有结点都是相互独立的,有两种操作: I u v:把v设为u的父节点,edge(u,v)的距离为ab ...
- 并查集(路径更新) LA 3027 Corporative Network
题目传送门 题意:训练指南P192 分析:主要就是一个在路径压缩的过程中,更新点i到根的距离 #include <bits/stdc++.h> using namespace std; c ...
- LA 3027 Corporative Network
这题感觉和 POJ 1988 Cube Stacking 很像,在路径压缩的同时递归出来的时候跟新distant数组 我发现我一直WA的原因是,命令结束是以字母o结束的,而不是数字0!! //#def ...
随机推荐
- 脱离Editor、VS等IDE如何编译UE4工程
在Windows平台下,我们从.uproject文件生成VS解决方案.sln文件 .uproject文件用于打开Editor .sln文件用于打开VS工程 对于有增加C++代码的工程,Editor中和 ...
- hbase参数调优
@ 目录 HBase参数调优 hbase.regionserver.handler.count hbase.hregion.max.filesize hbase.hregion.majorcompac ...
- 使用Rainbond实现离线环境软件交付
一.离线交付的痛点 在传统行业,如政府.能源.军工.公安.工业.交通等行业,为了防止数据泄露和运行安全考虑,一般情况下网络会采取内外网隔离的策略,以防范不必要的风险,毕竟在安全防护方面,网络物理隔离是 ...
- Yarn的Tool接口案例
目录 Yarn的Tool接口案例 Tool接口环境准备 1 新建Maven项目YarnDemo 编写代码 打包jar上传到集群 Yarn的Tool接口案例 Tool接口环境准备 之前写wordcoun ...
- LVM磁盘创建与扩容
以虚拟机为例 1.在虚拟机上添加新磁盘,点击虚拟机→设置->添加,最后如下图. 2.进入系统fdisk -l,查看当前磁盘信息 [root@master shell]# fdisk -l Dis ...
- flink-----实时项目---day07-----1.Flink的checkpoint原理分析 2. 自定义两阶段提交sink(MySQL) 3 将数据写入Hbase(使用幂等性结合at least Once实现精确一次性语义) 4 ProtoBuf
1.Flink中exactly once实现原理分析 生产者从kafka拉取数据以及消费者往kafka写数据都需要保证exactly once.目前flink中支持exactly once的sourc ...
- ssh : connect to host XXX.XXX.XXX.XXX port : 22 connect refused
初学者 写博客 如有不对之处请多多指教 我是要在俩个主机的俩个虚拟机上 用scp (security copy)进行文件远程复制. 但是 终端 提示 ssh : connect to host XXX ...
- 【leetocode】55. Jump Game
You are given an integer array nums. You are initially positioned at the array's first index, and ea ...
- [学习总结]2、android中的VelocityTracker(获得速率用的类)
参考资料:http://blog.jrj.com.cn/4586793646,5298605a.html 感谢这位兄弟! android.view.VelocityTracker主要用跟踪触摸屏事件( ...
- 【Linux】【Services】【Docker】网络
容器的网络模型: closed container: 仅有一个接口:loopback 不参与网络通信,仅适用于无须网络通信的应用场景,例如备份.程序调试等: --net none bridged co ...