
并查集
UCAS王小二
不念过去,不畏未来...
展开
-
Wannafly挑战赛26
链接:https://www.nowcoder.com/acm/contest/212/A作为「Misaka Network」的中心司令塔的 LastOrder出事了,为了维持 「Misaka Network」的正常工作,需要临时选出一个Sister作为中心司令塔。为了弥补能力上的不足,对于选出的Sister有一些要求。具体来说,平面上有 n 个 Sister,问能否找到一个Sister作为...原创 2018-10-16 17:00:33 · 203 阅读 · 0 评论 -
CodeForces - 791B 并查集或dfs
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).There are n members, numbered 1 thro原创 2017-04-29 12:04:06 · 473 阅读 · 0 评论 -
hdu1325 并查集-好题
A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following properties.Ther原创 2017-02-05 22:14:44 · 1707 阅读 · 7 评论 -
hdu 3038 How Many Answers Are Wrong
TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game. To begin with, TT shou原创 2017-02-15 21:18:39 · 1400 阅读 · 0 评论 -
uva 11987 Almost Union-Find
I hope you know the beautiful Union-Find structure. In this problem, you’re to implement something similar, but not identical. The data structure you need to write is also a collection of disjoint set原创 2017-02-06 22:18:37 · 303 阅读 · 0 评论 -
poj 2236 Wireless Network
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the n原创 2017-02-06 23:51:03 · 245 阅读 · 0 评论 -
HYSBZ - 2429 B - 聪明的猴子
在一个热带雨林中生存着一群猴子,它们以树上的果子为生。昨天下了一场大雨,现在雨过天晴,但整个雨林的地 表还是被大水淹没着,部分植物的树冠露在水面上。猴子不会游泳,但跳跃能力比较强,它们仍然可以在露出水面 的不同树冠上来回穿梭,以找到喜欢吃的果实。现在,在这个地区露出水面的有N棵树,假设每棵树本身的直径都 很小,可以忽略不计。我们在这块区域上建立直角坐标系,则每一棵树的位置由其所对应的坐原创 2017-03-03 23:11:39 · 548 阅读 · 0 评论 -
HDU 1272 小希的迷宫
Problem Description上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提高难度,小希希望任意两个房间有且仅有一条路径可以相通(除非走了回头路)。原创 2017-01-26 01:13:45 · 313 阅读 · 0 评论 -
hdu 1856 More is better
Mr Wang wants some boys to help him with a project. Because the project is rather complex,the more boys come, the better it will be. Of course there are certain requirements.Mr Wang selected a原创 2017-01-25 00:08:39 · 282 阅读 · 0 评论 -
hdu 1232 畅通工程
某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路?Input测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( < 1000 )和道路数目M;随后的M行对应M条道路,每行给出一对原创 2017-01-24 20:45:21 · 241 阅读 · 0 评论 -
HackerRank-even-tree【不带路径压缩的带权并查集】
题目描述给你一棵有n个节点的树(一个无环简单图),节点序号为1~n,根节点为1。请你找出一个最大的整数k,表示从这棵树上断掉k条边使其所有的子树的节点数都为偶数。输入第一行输入两个整数N,M。表示这棵树有N个节点和M条边。接下来有M行,每行输入两个整数u,v,表示u节点和v节点间有一条边相连。数据保证:2 ≤ n ≤ 100,并且所有的节点都在一棵树上。输入的树总能被分解为原创 2017-06-04 23:49:47 · 486 阅读 · 0 评论 -
poj 1182 食物链
食物链Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 68518 Accepted: 20251Description动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都原创 2017-03-09 13:54:52 · 268 阅读 · 0 评论 -
牛客国庆集训派对Day1
A:看样例过题;#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <vector>using namespace std;typedef long long LL;typedef pair<LL, LL>...原创 2018-10-03 09:47:35 · 173 阅读 · 0 评论 -
POJ 3984 迷宫问题【spfa+并查集】
定义一个二维数组: int maze[5][5] = {0, 1, 0, 0, 0,0, 1, 0, 1, 0,0, 0, 0, 0, 0,0, 1, 1, 1, 0,0, 0, 0, 1, 0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。 Input 一个5 × 5的二维数...原创 2018-03-19 21:43:14 · 277 阅读 · 0 评论 -
Wannafly挑战赛10 C 小H和游戏【延迟标记+并查集】
链接:https://www.nowcoder.com/acm/contest/72/C 来源:牛客网 题目描述 小H正在玩一个战略类游戏,她可以操纵己方的飞机对敌国的N座城市(编号为1~N)进行轰炸 敌国的城市形成了一棵树,小H会依次进行Q次轰炸,每次会选择一个城市A进行轰炸,和这座城市距离不超过2的城市都会受损(这里距离的定义是两点最短路径上的边...原创 2018-03-05 22:05:25 · 460 阅读 · 0 评论 -
CodeForces 828C String Reconstruction【并查集+思维】
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one.Ivan knows...原创 2018-03-15 21:14:41 · 279 阅读 · 0 评论 -
Codeforces Round #467 (Div. 2)【A B C D】
A - Olympiad The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine ...原创 2018-03-08 08:45:24 · 541 阅读 · 0 评论 -
HAUT 1285: 军团再临【并查集*逆向思维】
1285: 军团再临时间限制: 1 秒 内存限制: 128 MB提交: 56 解决: 20提交 状态 题目描述燃烧军团大举入侵艾泽拉斯,现以在艾星建立了大量的军事要塞,这些要塞通过若干个道路直接或间接连接。如果两个城市是连通的,那么它们处于同一连通块之中。现在抗魔联军发明了一种威力巨大的法术,每发动一次将会直接摧毁一个军事要塞,同时也摧毁与他相连的道路。每进行一次打原创 2017-08-07 10:02:31 · 1363 阅读 · 0 评论 -
nyoj42一笔画问题 【欧拉回路】
一笔画问题时间限制:3000 ms | 内存限制:65535 KB难度:4描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来。规定,所有的边都只能画一次,不能重复画。 输入第一行只有一个正整数N(N每组测试数据的第一行有两个正整数P,Q(P随后的Q行,每行有两个正整数A,B(0输原创 2017-03-17 00:59:12 · 407 阅读 · 0 评论 -
HDU - 1811 Rank of Tetris【并查集+拓扑*好题】
Rank of TetrisTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10101 Accepted Submission(s): 2885Problem Description自从Lele开发了R原创 2017-07-24 17:37:33 · 1606 阅读 · 0 评论 -
hdu 5631 Rikka with Graph【并查集】
题意: T组数据,一个数n,接下来n+1行表示边,问拆边后还能是这个图联通的方案数; 思路: n+1条边,由MST可知,只需n-1条边就可已使图联通,只需要枚举拆除一条边的情况和拆除两条边的情况就可以了;用结构体存边,拿枚举一条边举例吧,枚举每一条边被拆除后看看是否连通,拆两条边时同理;#include<cstdio>#include<cstring>#include<algorithm>原创 2017-08-01 22:03:25 · 280 阅读 · 0 评论 -
poj 1611 The Suspects
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to s原创 2017-01-24 20:39:50 · 226 阅读 · 0 评论