Live2d Test Env

随笔分类 -  并查集

摘要:题意:给定N,M,然后给出M组信息(u,v,l,r),表示u到v有[l,r]范围的通行证有效。问有多少种通行证可以使得1和N连通。 思路:和bzoj魔法森林有点像,LCT维护最小生成树。 开始和队友在想维护连通性,而不是维护树,这样好像会很麻烦。 队友yy了一个算法:用线段树模拟并查集维护连通性。( 阅读全文
posted @ 2019-08-10 16:41 nimphy 阅读(674) 评论(1) 推荐(0) 编辑
摘要:题意:给定一个N个节点的树,1<=N<=50000 每个节点都有一个权值,代表商品在这个节点的价格。商人从某个节点a移动到节点b,且只能购买并出售一次商品,问最多可以产生多大的利润。 思路:路径压缩,得到每个点到当前根的信息,然后更新即可。 有可以用倍增做。 很久前抄的代码。 阅读全文
posted @ 2019-07-24 11:57 nimphy 阅读(243) 评论(0) 推荐(0) 编辑
摘要:题意: 给定长度为N的海滩,然后有M做防御塔,给出每座塔的位置Xi,到海岸的距离Yi。 求防御塔上最小观测半径Ri,使得海滩被封锁。 思路:要使左边界和右边界连通。 很nice,可以二分+并查集做。 可以最小生成树做。 可以最短路做。 MST代码: #include<bits/stdc++.h> # 阅读全文
posted @ 2019-07-10 10:51 nimphy 阅读(279) 评论(0) 推荐(0) 编辑
摘要:A .Artwork pro:给定N*M的白色格子,然后Q次黑棒,输出每次加黑棒后白色连通块的数量。(N,M<1e3, Q<1e4) sol:倒着离线做,并查集即可。 A .Artwork pro:给定N*M的白色格子,然后Q次黑棒,输出每次加黑棒后白色连通块的数量。(N,M<1e3, Q<1e4) 阅读全文
posted @ 2019-04-04 19:20 nimphy 阅读(308) 评论(0) 推荐(0) 编辑
摘要:描述 有一个无向图,有n个点,m1条第一类边和m2条第二类边。第一类边有边权,第二类边无边权。请为第二类的每条边定义一个边权,使得第二类边可能全部出现在该无向图的最小生成树上,同时要求第二类边的边权总和尽可能大。注:第二类边不会形成环 输入 第一行三个数n,m2,m1 接下来m2行,每行两个数,描述 阅读全文
posted @ 2019-01-02 17:15 nimphy 阅读(244) 评论(0) 推荐(0) 编辑
摘要:Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely ed 阅读全文
posted @ 2018-12-26 11:13 nimphy 阅读(554) 评论(0) 推荐(0) 编辑
摘要:题意:给定无向图,让你给点加权(1,2,3),使得每条边是两端点点权和维奇数。 思路:一个连通块是个二分图,判定二分图可以dfs,并查集,2-sat染色。 这里用的并查集(还可以带权并查集优化一下,或者干脆用dfs)。 计数的时候每个连通块单独考虑,我们从连通块的第一个点开始dfs,如果是该填奇数点 阅读全文
posted @ 2018-12-16 14:38 nimphy 阅读(543) 评论(0) 推荐(0) 编辑
摘要:Now and then you play the following game with your friend. Your friend writes down a sequence consisting of zeroes and ones. You choose a continuous s 阅读全文
posted @ 2018-12-04 21:48 nimphy 阅读(456) 评论(0) 推荐(0) 编辑
摘要:3296: [USACO2011 Open] Learning Languages Description 农夫约翰的N(2 <= N<=10,000)头奶牛,编号为1.. N,一共会流利地使用M(1<= M <=30,000)种语言,编号从1 .. M.,第i头,会说K_i(1 <= K_i<= 阅读全文
posted @ 2018-11-29 21:07 nimphy 阅读(239) 评论(0) 推荐(0) 编辑
摘要: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 makin 阅读全文
posted @ 2018-09-03 16:07 nimphy 阅读(474) 评论(0) 推荐(0) 编辑
摘要:Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph G 阅读全文
posted @ 2018-08-30 16:45 nimphy 阅读(298) 评论(0) 推荐(0) 编辑
摘要:Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers th 阅读全文
posted @ 2018-08-30 13:18 nimphy 阅读(247) 评论(0) 推荐(0) 编辑
摘要:For a connected undirected weighted graph G, MST (minimum spanning tree) is a subgraph of G that contains all of G's vertices, is a tree, and sum of i 阅读全文
posted @ 2018-08-27 22:21 nimphy 阅读(508) 评论(0) 推荐(0) 编辑
摘要:题意:给定N点,M边,求添加最少的边使之变为连通图的方案数。 思路:注意题目给出的M边可能带环,即最后生成的不一定是一棵树。但是影响不大。根据矩阵树定理,我们知道生成树的数量=N^(N-2),即点数^(连通数-2)。 此题把已经连通的看成一个整体,就可以得到数量为N^(cnt-2),然后考虑连通块内 阅读全文
posted @ 2018-08-21 17:07 nimphy 阅读(531) 评论(0) 推荐(0) 编辑
摘要:Taplu and Abhishar loved playing scrabble. One day they thought of inventing a new game using alphabet tiles. Abhishar wrote a string using tiles and 阅读全文
posted @ 2018-05-25 17:08 nimphy 阅读(439) 评论(0) 推荐(0) 编辑
摘要:On September 22, 2004, Oceanic Flight 815 crashed on a mysterious island somewhere in the pacific. There actually were survivors in the crash , N surv 阅读全文
posted @ 2018-04-30 16:31 nimphy 阅读(256) 评论(0) 推荐(0) 编辑
摘要:关键词:并查集,二分图,树剖,树上差分,LCA,搜索。 例题一: CodeForces-85E:Guard Towers 题意:给定平面上N个点(N<=5000),以及N个点的坐标。现在可以把每个点染成红色或者蓝色。求最小化同色点的最大距离,且求出相应的方案数。 思路:二分答案L,把距离大于等于L的 阅读全文
posted @ 2018-03-18 16:30 nimphy 阅读(697) 评论(0) 推荐(0) 编辑
摘要:We already know of the large corporation where Polycarpus works as a system administrator. The computer network there consists of n computers and m ca 阅读全文
posted @ 2018-03-12 16:30 nimphy 阅读(331) 评论(0) 推荐(0) 编辑
摘要:描述 小Hi给小Ho邮寄了一个天平。收到天平后,小Ho想知道天平在运输过程中是否损坏,为此它准备了A类物品和B类物品共n个(可能只有A类物品,也可能只有B类物品),但无法确定一个物品是哪一类。A类物品的质量都相同,B类物品的质量也相同,但A类物品与B类物品的质量不同。现将n个物品从1到n编号,用天平 阅读全文
posted @ 2018-02-17 17:36 nimphy 阅读(264) 评论(0) 推荐(0) 编辑
摘要:There are N cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chosen some paths and wants to 阅读全文
posted @ 2017-12-24 21:08 nimphy 阅读(482) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示