[Codeforces]856D - Masha and Cactus】的更多相关文章

题面传送门 题意: 给你一棵 \(n\) 个顶点的树和 \(m\) 条带权值的附加边 你要选择一些附加边加入原树中使其成为一个仙人掌(每个点最多属于 \(1\) 个简单环) 求你选择的附加边权值之和的最大值. \(n \in [3,2 \times 10^5]\),\(m \in [0,2 \times 10^5]\) 很容易发现,如果你选择一条端点为 \(u,v\) 的附加边,那么 \(u\) 到 \(v\) 路径上所有点都会被包含进一个简单环. 那么题目变为:有 \(m\) 条路径,你要选择…
题目大意:给出一棵树和若干条可以加入的边,要求加入若干条边使图是仙人掌并且加入的边权和最大,仙人掌定义为没有一个点属于超过1个环.(n,m<=200,000) 做法:这题的仙人掌跟平时见到的不太一样,是以点为判定条件,比较坑--发现与选若干条不相交的链权值和最大等价,dp,f[i]表示i的子树内最大权值和,每次枚举一条lca为i的链转移,需要求出这条链以外的子树的dp值,树剖后线段树维护每个点轻儿子dp值之和,重儿子的暴力算一算就可以了,复杂度O((n+m)log^2). 代码: #includ…
A. Masha and Bears time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car…
2017 Russian Code Cup (RCC 17), Final Round A Set Theory 思路:原题转换一下就是找一个b数组,使得b数组任意两个数的差值都和a数组任意两个数的差值相等 根据题目数据范围, 肯定可以构造一个1, 1+d, 1+2d, 1+3d, ... , 1+(n-1)*d的序列 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits…
C. Masha and two friends time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Recently, Masha was presented with a chessboard with a height of nn and a width of mm. The rows on the chessboard ar…
E. Cactus   A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle. A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i…
231E - Cactus 给一个10^5个点的无向图,每个点最多属于一个环,规定两点之间的简单路:从起点到终点,经过的边不重复 给10^5个询问,每个询问两个点,问这两个点之间有多少条简单路. 挺综合的一道题目,无向图连通分量,缩点,LCA 都考察到了.. 因为每个点最多属于一个环,因此把所有环缩点,就可以得到一棵树 然后对于每个询问,用LCA查找从起点到终点有多少个环 并查集处理的时候挂了一发,注意LCA时合并两个并查集,根节点深度小的作为父亲.. #include<cstdio> #in…
B. Cubes for Masha time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Absent-minded Masha got set of n cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from…
C. Masha and two friends 题目链接:https://codeforc.es/contest/1080/problem/C 题意: 给出一个黑白相间的n*m的矩阵,现在先对一个子矩阵颜色变为白色,然后再对一个子矩阵颜色变为黑色,问最终白色格子和黑色格子有多少? 题解: 定义w(a,b)为(1,1)到(a,b)中白色的数量,通过观察找规律可以发现w(a,b)=((b+1)/2)*((a+1)/2)+(b/2)*(a/2). 然后b(a,b)就是格子总数量减去w(a,b). 现…
CodeForces - 789B 当时题意理解的有点偏差,一直wa在了14组.是q等于0的时候,b1的绝对值大于l的时候,当b1的绝对值大于l的时候就应该直接终端掉,不应该管后面的0的. 题意告诉你b1,q,l,m然后b1和q是一个等比序列的首项和公比,然后l是这个序列出现的数绝对值的最大值.m代表序列有m个数不能被计算在内.问你能写出的最多的序列的元素个数.如果有无限多个输出inf. 分析一下,首先就是无限多个出现的情况. 1.b1==0.此时的序列是无限个0,只要0不在m个数中就是inf,…