Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7469 Accepted: 3620 Description You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You ar…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2818 题意:有N个块,每次有两个操作: M x y表示把x所在的那一堆全部移到y所在的那一堆的下方. C x 询问在x下方有多少个方块. 用并查集,在路径压缩的时候后序更新当前块下有多少个其他块,注意这里“当前块下”其实和并查集是相反的,也就是父亲节点在儿子下面. 需要额外维护一个量:某一堆的块的总数,这个在unite操作的时候,如果不是同一个根,直接将一部分加到另一部分上就可以. /* ━━━━━…
#include<iostream> //由于拆除并查集的方法太难或者没有#include<cstdio> //可以先将所有没有拆的桥连接 再逆向操作 断开变成连接 反向输出#include<map> using namespace std; const int Hash = 10000;const int N = 10005;const int M = 20005; map<int, bool>mp; //mp用来标记该桥是否会被拆,如果会被拆就先不要连接…
Connections in Galaxy War In order to strengthen the defense ability, many stars in galaxy allied together and built many bidirectional tunnels to exchange messages. However, when the Galaxy War began, some tunnels were destroyed by the monsters from…
Building Block Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5811 Accepted Submission(s): 1790 Problem Description John are playing with blocks. There are N blocks (1 <= N <= 30000) number…
题意: 给你一些点,还有一些边,每个点上都有一个权值,然后有一些询问,分为两种, query a 询问与a直接或者间接想连的点中最大权值的是那个点,输出那个点,如果那个点的权值小于等于a的权值,那么就输出-1,还有另一种操作就是destroy a b意思是删除a b的关系. 思路: 比较基础的并查集题目,看到删边,很容易想到逆向离线处理,先把最终的状态建立出来,然后对于询问逆向处理,正向是删边,那么逆向肯定是加边了,更新最优的话也是比较简单的并查集小变种(也就是平时说的带…
Problem Description John are playing with blocks. There are N blocks ( <= N <= ) numbered ...N.Initially, there are N piles, and each pile contains one block. Then John <= P <= ). There are two kinds of operation: M X Y : Put the whole pile co…
D-City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 1315 Accepted Submission(s): 496 Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D…
http://acm.hdu.edu.cn/showproblem.php?pid=4496 题意: 给出n个顶点m条边的图,每次选择一条边删去,求每次删边后的连通块个数. 思路: 离线处理删边,从后往前处理变成加边,用并查集维护连通块个数.其实这题和BZOJ 1015差不多. #include<iostream> #include<cstdio> #include<cstring> using namespace std; int n, m, tot, num; ],…