Corporative Network_并查集】的更多相关文章

Description A very big corporation is developing its corporative network. In the beginning each of the N enterprises of the corporation, numerated from 1 to N, organized its own computing and telecommunication center. Soon, for amelioration of the se…
A very big corporation is developing its corporative network. In the beginning each of the N enterprises of the corporation, numerated from 1 to N, organized its own computing and telecommunication center. Soon, for amelioration of the services, the…
Corporative Network Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status] Description   A very big corporation is developing its corporative network. In the beginning each of the N enterprises of th…
这题比较简单,注意路径压缩即可. AC代码 //#define LOCAL #include <stdio.h> #include <algorithm> using namespace std; const int maxn = 20000+5; int par[maxn], dis[maxn]; void init(int n) { for(int i = 0; i <= n; i++) { par[i] = i; dis[i] = 0; } } int findRoot…
                     Corporative Network A very big corporation is developing its corporative network. In the beginning each of the N enterprisesof the corporation, numerated from 1 to N, organized its own computing and telecommunication center.Soon,…
Corporative Network Problem's Link Mean: 有n个结点,一开始所有结点都是相互独立的,有两种操作: I u v:把v设为u的父节点,edge(u,v)的距离为abs(u-v)%1000; E u:输出u到根节点的距离. analyse: 经典的并查集习题!Rujia挑选的题目真心不错. 做法很巧妙,但是要对并查集和路径压缩有深入的了解才能想到这种做法. 由于每次E操作都会加入一个新的结点,而且每次都是把一个结点指向另一个结点,所以说不会同时存在两个或两个以上…
A very big corporation is developing its corporative network. In the beginning each of the N enterprises of thecorporation, numerated from 1 to N, organized its own computing and telecommunication center. Soon, foramelioration of the services, the co…
<题目链接> 题目大意: n个节点,若干次询问,I x y表示从x连一条边到y,权值为|x-y|%1000:E x表示询问x到x所指向的终点的距离.   解题分析: 与普通的带权并查集类似,但是要注意的是,在进行查询操作时,也要调用一下find函数,因为以前的uion操作可能将某些值改变了,所以find()操作是将这些节点全部更新一遍,得到它们的真实值. #include <cstdio> #include <cmath> +; int father[maxn],dis…
题意: 有 n 个节点,初始时每个节点的父节点都不存在,你的任务是执行一次 I 操作 和 E 操作,含义如下: I  u  v   :  把节点 u  的父节点设为 v  ,距离为| u - v | 除以 1000 的余数. E u   : 询问u 到根节点的距离. 解题思路: 因为题目只查询节点到根节点的距离,所以每棵树处理根节点不能换之外.其他节点的位置可以随意改变,这恰好符合并查集的特点,但是附加了一点东西....在两点之间有了一个附加的权值(距离)..所以就是加权并查集了..题目给的是节…
题意:一个企业要去收购一些公司把,使的每个企业之间互联,刚开始每个公司互相独立 给出n个公司,两种操作 E I:询问I到I它连接点最后一个公司的距离 I I J:将I公司指向J公司,也就是J公司是I公司的上级,距离为abs(I-J)%1000(貌似G++不支持abs,PE了两发) 思路:转化一下题意就行了,首先刚开始的时候每个公司都是独立的,I操作就是并查集中合并操作,将I这课树并到J这个树上, E操作要求的东西就是 I到I的根节点的距离,先看一个没有路径压缩直接暴力的方法把.(本以为不会过的,…