
数据结构_并查集
just_sort
Acdream.
展开
-
BZOJ 1104: [POI2007]洪水pow 并查集
Description AKD市处在一个四面环山的谷地里。最近一场大暴雨引发了洪水,AKD市全被水淹没了。Blue Mary,AKD市的市 长,召集了他的所有顾问(包括你)参加一个紧急会议。经过细致的商议之后,会议决定,调集若干巨型抽水机, 将它们放在某些被水淹的区域,而后抽干洪水。你手头有一张AKD市的地图。这张地图是边长为m*n的矩形,被划分 为m*n个1*1的小正方形。对于每个小正方形原创 2017-02-07 16:01:13 · 1017 阅读 · 0 评论 -
HDU 5631 Rikka with Graph 并查集
题意: 众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的:给出一张 n 个点 n+1 条边的无向图,你可以选择一些边(至少一条)删除。现在勇太想知道有多少种方案使得删除之后图依然联通。当然,这个问题对于萌萌哒六花来说实在是太难了,你可以帮帮她吗?解法: n个点,n+1条边,显然你最多就只能删除两个点让他成为一棵树所以我们就直接暴力枚举两个点就好了,然后我们再用原创 2017-03-03 20:13:25 · 777 阅读 · 0 评论 -
Educational Codeforces Round 7 C. Not Equal on a Segment 并查集
C. Not Equal on a Segment time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputYou are given array a with n integers and m queries. The i-原创 2017-03-03 20:36:00 · 503 阅读 · 0 评论 -
Educational Codeforces Round 5 C. The Labyrinth BFS,并查集
题目链接:见这里 C. The Labyrinth time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputYou are given a rectangular field of n × m cells. Each cel原创 2017-03-04 09:18:08 · 492 阅读 · 0 评论 -
Codeforces Round #181 (Div. 2) B. Coach 带权并查集
题目链接:见这里 B. Coach time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputA programming coach has n students to teach. We know that n is di原创 2017-03-04 09:55:21 · 832 阅读 · 0 评论 -
BZOJ 2733 2733: [HNOI2012]永无乡 平衡树启发式合并
Description永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示。某些岛之间由巨大的桥连接,通过桥可以从一个岛 到达另一个岛。如果从岛 a 出发经过若干座(含 0 座)桥可以到达岛 b,则称岛 a 和岛 b 是连 通的。现在有两种操作:B x y 表示在岛 x 与岛 y 之间修建一座新桥。Q x k 表示原创 2017-03-04 10:37:37 · 576 阅读 · 0 评论 -
Educational Codeforces Round 1 D. Igor In the Museum BFS,带权并查集
题目链接:见这里 D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputIgor is in the museum and he wants to see as many pic原创 2017-03-04 11:33:10 · 843 阅读 · 0 评论 -
Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph 高维并查集,STL连招
题目链接:见这里 题意: 给你一个图,然后有重边,每条边有一种颜色,然后每次查询两个点之间有多少种颜色是把这俩点直接相连的 解法: 这里要用到高维的并查集,定义fa[u][c]=v表示节点u的颜色c属于集合v,由于无法开出这么大的二维数组,且实际边的数量很少,可以考虑使用map。每次加边的时候,如果该节点u的颜色c不属于任何集合,则将u作为当前集合的根。每次加入一条边,相当于合并两个不同的集合原创 2017-03-04 14:02:40 · 811 阅读 · 0 评论 -
1202: [HNOI2005]狡猾的商人 带权并查集
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1202题意:有一本记录了n个月的账本,偷看了m次每次记住了一个区间[x,y]的和,问这本帐是否是假账。做法:神奇并查集。用并查集维护一下类似前缀和的东西,如果当前是[x,y],那么从x-1向y连一条边,v[x]表示s[x]-s[q]的值,s是前缀和,q是x所在联通块的根,如果当前的x和y是在一原创 2017-04-11 13:11:32 · 410 阅读 · 0 评论 -
HDU 5652 二分+并查集+BFS
题目链接:看这里吧,中文题 解法: 以前做过,BC的一道题,今天复习并查集重写一次。 然后比较显然的就是二分+判断是否连通,判断是否连通用并查集和bfs都可以。//HDU 5652#include <bits/stdc++.h> using namespace std; const int maxn = 510; int n, m, q, vis[maxn][maxn]; char s[maxn]原创 2017-03-03 19:37:27 · 455 阅读 · 0 评论 -
Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 暴力,二分图,并查集
题目链接:见这里 D. Dividing Kingdom II time limit per test 6 seconds memory limit per test 256 megabytes input standard input output standard outputLong time ago, there was a great kingdom and it was原创 2017-03-03 18:58:03 · 410 阅读 · 0 评论 -
BZOJ 1015 星球大战 离线并查集 好题
Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系。某一天,凭着一个偶然的 机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球。这些星球通过特殊的以太隧道互相直 接或间接地连接。 但好景不长,很快帝国又重新造出了他的超级武器。凭借这超级武器的力量,帝国开始有计划 地摧毁反抗军占领的星球。由于星球的不断被摧毁,两个星球之间的通讯通道原创 2017-01-18 16:20:26 · 785 阅读 · 0 评论 -
BZOJ 1116: [POI2008]CLO 并查集
DescriptionByteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 你要把其中一些road变成单向边使得:每个town都有且只有一个入度 Input第一行输入n m.1 <= n<= 100000,1 <= m <= 200000 下面M行用于描述M条边. OutputTAK或者NIE 常做POI的同学,应该知原创 2017-02-09 23:21:05 · 395 阅读 · 0 评论 -
BZOJ 1050: [HAOI2006]旅行comf 贪心,并查集
Description 给你一个无向图,N(N<=500)个顶点, M(M<=5000)条边,每条边有一个权值Vi(Vi<30000)。给你两个顶点S和T ,求一条路径,使得路径上最大边和最小边的比值最小。如果S和T之间没有路径,输出”IMPOSSIBLE”,否则输出 这个比值,如果需要,表示成一个既约分数。 备注: 两个顶点之间可能有多条路径。 Input 第一行包含两个正整数,N和M。原创 2017-01-21 15:13:32 · 364 阅读 · 0 评论 -
POJ 1182 食物链 带权并查集入门
Description 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。 有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是”1 X Y”,表示X和Y是同类。 第二种说法是”2 X Y”,表示X吃Y。 此人对N个动物,用上述两种说法原创 2017-03-02 16:53:12 · 647 阅读 · 0 评论 -
Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary 并查集
D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard outputMahmoud wants to write a new dictionary that contains n原创 2017-03-03 09:17:23 · 781 阅读 · 0 评论 -
Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array 带权并查集
C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputYou are given an array consisting of n non-negative integers a1,原创 2017-03-03 09:36:11 · 466 阅读 · 0 评论 -
UVALive 6906 Cluster Analysis 并查集
题目地址:见这里 DescriptionCluster analysis, or also known as clustering, is a task to group a set of objects into one or more groups such that objects belong to a same group are more similar compared to ob原创 2017-03-03 13:08:41 · 489 阅读 · 0 评论 -
UVALive 6910 Cutting Tree(并查集)
题目链接:https://vjudge.net/problem/UVALive-6910DescriptionTree in graph theory refers to any connected graph (of nodes and edges) which has no simple cycle, while forest corresponds to a collection of on原创 2017-03-03 13:24:55 · 502 阅读 · 0 评论 -
2017多校第4场 HDU 6074 Phone Call 并查集,LCA
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6074 题意:给你一棵树,然后给你M个条件,每次给出a,b,c,d,cost,表示从a-->b,c-->d的路径中的点,可以互相到达,花费是cost,到达具有传递性 ,现在问你从1节点最多可以到达哪些节点,最小花费是多少。 解法:看着官方题解学的。 #include using原创 2017-08-05 19:36:35 · 975 阅读 · 0 评论