![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
并查集
live4m
老菜逼了
展开
-
CodeForces 1263 D.Secret Passwords (并查集)
题意:给n个字符串,如果两个字符串都含有某个字母,则这两个字符串等价且如果a和b等价,b和c等价,则a和c等价n个串有多少种不等价的串思路:容易想到并查集,且假设串为abc,则含abc字符的串肯定在同一集合中但如果对于每个串,O(n2)把串中含有的字母合并为一个集合,肯定超时新开26个节点表示26个字母的集合遍历每个串,将串合并到相应的字母集合里面就行了code:#inclu...原创 2019-12-01 11:29:51 · 239 阅读 · 0 评论 -
Comet OJ-Contest #13 C2.「佛御石之钵 -不碎的意志-」(困难版) (并查集)
题意:给出一个 n 行 m 列的 01 矩阵。有 q 次操作,每次操作选取一个子矩阵,将子矩阵变为全 1,每次操作后输出当前连通块个数数据范围:n,m<=1e3q<=3e4思路:code:...原创 2019-11-19 15:12:56 · 115 阅读 · 0 评论 -
CodeForces 1156 D.0-1-Tree(并查集)
D.0-1-TreeYou are given a tree (an undirected connected acyclic graph) consisting of n vertices and n−1 edges. A number is written on each edge, each number is either 0 (let’s call such edges 0-edges...原创 2019-11-14 18:11:10 · 200 阅读 · 0 评论 -
CodeForces437 D.The Child and Zoo (并查集)
D.The Child and ZooOf course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The i-th area contains ai animals in it. Also there are m roads in the zoo, and each...原创 2019-10-29 21:31:22 · 217 阅读 · 0 评论 -
CodeForces356 A.Knight Tournament (并查集)
A.Knight TournamentHooray! 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 th...原创 2019-10-24 23:39:00 · 140 阅读 · 0 评论 -
CodeForces1131 F.Asya And Kittens (并查集)
F.Asya And KittensAsya loves animals very much. Recently, she purchased n kittens, enumerated them from 1 and n and then put them into the cage. The cage consists of one row of n cells, enumerated wi...原创 2019-10-21 19:17:26 · 176 阅读 · 0 评论 -
nowcoder 小C的周末 (并查集+map)
链接:https://ac.nowcoder.com/acm/problem/15976来源:牛客网题目描述愉快的周末到了,小C和他的N-1个朋友买了M个游戏,游戏编号从1~M。每个游戏都是多人游戏,他们打算周末一起打游戏。小C的每个朋友都决定好了要玩哪一款游戏(会有一组人打同一款游戏),并且每人手上都有一台游戏机,这种游戏机可以通过特定的游戏机连接线连接起来。但是,他们面临着一个问题:...原创 2019-10-11 12:01:06 · 451 阅读 · 0 评论 -
CodeForces1209 D.Cow and Snacks (并查集)
D.Cow and SnacksThe legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring ou...原创 2019-09-16 16:05:32 · 502 阅读 · 0 评论 -
bzoj2733 永无乡 (并查集+线段树合并)
问题描述永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示。某些岛之间由巨大的桥连接,通过桥可以从一个岛 到达另一个岛。如果从岛 a 出发经过若干座(含 0 座)桥可以到达岛 b,则称岛 a 和岛 b 是连 通的。现在有两种操作:B x y 表示在岛 x 与岛 y 之间修建一座新桥。Q x k 表示询问当前与...原创 2019-09-13 18:27:28 · 144 阅读 · 0 评论 -
CodeForces - 1213 G.Path Queries (并查集)
题意:给一棵n个顶点的树,m个询问,每个询问给k,图中有多少对点对u,v(u<v)满足u,v路径上的最长边不大于k分析:结构体存储所有边和所有询问对边从小到大排序,对询问按k从小到大排序遍历所有询问对于每个询问中的k,将所有边权小于等于k的边的端点用并查集合并成同一连通块此时每个 连通块中任意点对的最长边都小于k,假设一个连通块中点的个数为x,则点对数量为x(x-1)/2...原创 2019-08-31 18:02:06 · 432 阅读 · 0 评论 -
hdu2818与hdu3635 (带权并查集)
hdu2818约翰正在玩积木。有N个block (1 <= N <= 30000)编号为1…N .最初有N根桩,每根桩包含一个块。然后John做一些运算P次(1 <= P <= 1000000)。有两种操作:mxy:把包含X块的整个堆放到包含Y块的堆上,如果X和Y在同一堆上,就忽略这个命令。计算方块X下的方块数要求您找出每个C操作的输出。输入第一行包含整数P,然...原创 2019-08-03 08:33:46 · 203 阅读 · 0 评论 -
poj1679 The Unique MST (判断最小生成树是否唯一)(kruskal)
poj1679问题描述给出一个连通无向图,判断它的最小生成树是否唯一。定义1(生成树):考虑一个连通的无向图G = (V, E)。V ’ = V。T是连通的非循环的。定义2(最小生成树):考虑一个边权连通无向图G = (V, E)。G的最小生成树T = (V, E’)是总代价最小的生成树。T的总代价是E’中所有边的权值之和。输入第一行包含一个整数t (1 <= t <...原创 2019-06-04 23:08:48 · 332 阅读 · 0 评论 -
poj1456 Supermarket (贪心)(并查集优化)
题意先给n然后n个商品的价值和贩卖截止时间。一天只能卖一件问能卖出的最大价值是多少Sample Input4 50 2 10 1 20 2 30 17 20 1 2 1 10 3 100 2 8 25 20 50 10Sample Output80185分析:贪心。先把所有商品按价值排序,先卖价值最高的。卖出去之后如果下一件商品的截止时间...原创 2019-06-08 19:26:01 · 134 阅读 · 0 评论 -
hdu1811 Rank of Tetris (一般并查集+拓扑排序)带注释
Rank of Tetris链接:Rank of TetrisRank of TetrisProblem Description自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球。为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜,定时更新,名堂要比福布斯富豪榜还响。关于如何排名,这个不用说都知...原创 2019-05-11 11:48:23 · 171 阅读 · 0 评论