Restructuring Company Even the most successful company can go through a crisis period when you have to make a hard decision — to restructure, discard and merge departments, fire employees and do other unpleasant stuff. Let's consider the following mo…
题意:给定 3 种操作, 第一种 1 u v 把 u 和 v 合并 第二种 2 l r 把 l - r 这一段区间合并 第三种 3 u v 判断 u 和 v 是不是在同一集合中. 析:很容易知道是用并查集来做,但是如果单纯的用并查集,肯定是要超时的,所以要用链表,如果合并了,就把链表指向, 这样就搞定了这个题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #i…
题目链接: D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Even the most successful company can go through a crisis period when you have to make a hard decision — to re…
D. Restructuring Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/566/problem/D Description Even the most successful company can go through a crisis period when you have to make a hard decision — to restructure, disca…
http://codeforces.com/contest/566/problem/D D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Even the most successful company can go through a crisis period when yo…
Knight Tournament Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple pea…
BZOJ4668: 冷战 题意: 给定 n 个点的图.动态的往图中加边,并且询问某两个点最早什 么时候联通,强制在线. 还可以这样乱搞 并查集按秩合并的好处: 深度不会超过\(O(\log n)\) 树的结构保持较稳定 -> 虽说连边的时候依旧是祖先来连边,但连边不会改变原来的结构,并且(u,v)路径上会经过新连的边 于是就可以乱搞了 维护一个按秩合并的并查集,给连边操作加时间戳,查询的时候暴力求路径上时间戳最大值 PS:暴力lca也是需要deep PS2:按秩合并是看高度的吧,为什么我的好慢?…
[HNOI2012]永无乡 每个联通块的点集用动态开点线段树维护 并查集维护图 合并时把线段树也合并就好了. #include<iostream> #include<cstdio> #include<cstring> #include<cctype> #define re register #define gc getchar using namespace std; void chread(char &x){ char c=gc(); while(…
题目描述 1946 年 3 月 5 日,英国前首相温斯顿·丘吉尔在美国富尔顿发表“铁幕演说”,正式拉开了冷战序幕. 美国和苏联同为世界上的“超级大国”,为了争夺世界霸权,两国及其盟国展开了数十年的斗争.在这段时期,虽然分歧和冲突严重,但双方都尽力避免世界范围的大规模战争(第三次世界大战)爆发,其对抗通常通过局部代理战争.科技和军备竞赛.太空竞争.外交竞争等“冷”方式进行,即“相互遏制,不动武力”,因此称之为“冷战”. Reddington 是美国的海军上将.由于战争局势十分紧张,因此他需要时刻关…
思路: 1. 并查集+线段树合并 记得f[LCA]==LCA的时候 f[LCA]=fa[LCA] 2.LCT(并不会写啊...) //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; ],v[N*],tot,deep[N],num[N],f[N],fa[N][]; long long ans; int lca(int x,int y)…