题目传送门 题意:训练指南P192 分析:主要就是一个在路径压缩的过程中,更新点i到根的距离 #include <bits/stdc++.h> using namespace std; const int N = 2e4 + 5; struct DSU { int rt[N], d[N]; void init(void) { memset (rt, -1, sizeof (rt)); memset (d, 0, sizeof (d)); } int Find(int x) { if (rt[x…
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…
·一些很可爱的询问和修改,放松地去用并查集解决. ·英文题,述大意: 输入n(5<=n<=20000)表示树有n个节点,并且会EOF结束地读入不超过 20000个操作,一共有两种:    ①I v u:表示将v的父亲节点设置为u(在这之前v没有爸爸),边权设置为abs(v-u)%1000.    ②E u:表示询问u到当前它所在树的根节点的距离. ·分析:      为了记录当前一系列加边操作后所有的点的位置情况(因为你随时可能回答询问啊),根据这道题的点关系特点[只在乎点和其根节点的信息],…
这题感觉和 POJ 1988 Cube Stacking 很像,在路径压缩的同时递归出来的时候跟新distant数组 我发现我一直WA的原因是,命令结束是以字母o结束的,而不是数字0!! //#define LOCAL #include <algorithm> #include <cstdio> using namespace std; + ; int parent[maxn], distant[maxn]; int GetParent(int a) { if(parent[a]…
http://poj.org/problem?id=1988 Cube Stacking Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 19122   Accepted: 6664 Case Time Limit: 1000MS Description Farmer John and Betsy are playing a game with N (1 <= N <= 30,000)identical cubes la…
Segment set Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3457    Accepted Submission(s): 1290 Problem Description A segment and all segments which are connected with it compose a segment set.…
http://codeforces.com/contest/828/problem/C [题意] [思路] 因为题目保证一定有解,所有优化时间复杂度的关键就是不要重复染色,所以我们可以用并查集维护区间,把确定的点的父亲节点设为下一个点,这样访问过的点的根节点都是没访问过的点. 与上一题是同样的思路,用并查集路径压缩, 要求字典序最小,可以最初给每个字符都赋值'a' 判断字符串最长是多少,最后加'\0' [Accepted] #include<iostream> #include<cstd…
UVAlive 3027 Corporative Network 题目:   Corporative Network Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 3450   Accepted: 1259 Description A very big corporation is developing its corporative network. In the beginning each of the N ent…
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 #inc…