很有趣的一道题. 首先可以对每个叶子进行编号.按照DFS到的顺序即可.(假设从 $1$ 到 $k$) 然后对每个点求出它管辖的所有叶子的编号.因为是DFS序所以这一定是个区间.设点 $u$ 的这个区间是 $[l_u,r_u]$. 区间加操作,考虑差分,那么每个点的操作就变成了 $l_u$ 加一个数,$r_u+1$ 减一个数.(此时也要考虑 $k+1$) 那么题目要求就变成了所有数都变成 $0$. 感受一下,把 $(l_u,r_u+1,c_u)$ 看做一条带权边,那么当且仅当选择的边构成连通图时满…
沙发~~ 题意简述 给你一棵有根树,定义叶子为度数为1的点. 你可以以$ w_x \(的代价控制\)x\(点.选择控制之后可以给它的子树里的叶子加 上\)t (t \in Z )$. 你要以最小的总代价使得:另一个人在叶子上任意放数,你都可以把它 们都变成0. 最后输出最小的总代价,以及有多少点可能被控制,以及每个可能被控制的点的编号 思路索引 首先,我们可以把所有的叶子节点按照 dfs序 抽象成一个序列 接下来,我们可以很神奇的发现,每一个点就对应着一个区间这不是废话吗 然后,选择某个区间后,…
比赛时候还是太慢了……要是能做快点就能上分了 Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from 11 to nn. For every edge ee of this tree, Monocarp has written two numbers: the ma…
Binary Tree 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5573 Description The Old Frog King lives on the root of an infinite tree. According to the law, each node should connect to exactly two nodes on the next level, forming a full binary tree. S…
这场CF怎么这么多构造题…… 题目链接:CF原网 洛谷 题目大意:给定两个长度为 $n$ 的序列 $c$ 和 $t$.每次我们可以对 $c_i(2\le i<n)$ 进行一次操作,也就是把 $c_i$ 变成 $c_i'=c_{i-1}+c_{i+1}-c_i$.问 $c$ 能否在若干次操作后变成 $t$. $1\le n\le 10^5,1\le c_i,t_i\le 2\times 10^9$. 很容易考虑差分.我们设 $d_i=c_i-c_{i-1},s_i=t_i-t_{i-1}(2\le…
C - Upgrading Tree 我发现我构造题好弱啊啊啊. 很明显能想到先找到重心, 然后我们的目标就是把所有点接到重心的儿子上,让重心的儿子子树变成菊花图, 这个先把重心到儿子的边连到 i , 然后把 i 到 其 fa 的边连到重心的儿子上, 一直循环就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL p…
C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he ca…
link:http://acm.hdu.edu.cn/showproblem.php?pid=4671 其实是不难的那种构造题,先排第一列,第二列从后往前选. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <algorithm> #…
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) i…
这是一道蛮基础的构造题. - k         +(k - 1)      -(k - 2) 1 + k ,    1 ,         k ,             2,    ................... \  /        \  /           \  / k          k-1          k-2 如图所示,先构造第一个数,就是1 + k, 然后接下来每个数字和上个数相差k , k -1 , k -2 这样下来,最后一个数字就是一个中间的数字,过程就…