题目链接:https://codeforces.com/contest/1363/problem/E 题意 有一棵 $n$ 个结点,根为结点 $1$ 的树,每个结点有一个选取代价 $a_i$,当前 $b_i$,目标数字 $c_i$ .每次可以选择以一个结点为根节点的子树中的 $k$ 个结点交换它们的 $b_i$,总代价为 $k \times a_{root}$ ,判断能否把所有结点都变为目标数字以及最小代价. 题解 因为每棵子树都可以被包含进更大的子树中,所以对于每棵子树的根节点,它的最小选取代…
题意: 给你n个节点,这n个节点构成了一颗以1为树根的树.每一个节点有一个初始值bi,从任意节点 i 的子树中选择任意k个节点,并按他的意愿随机排列这些节点中的数字,从而产生k⋅ai 的成本.对于一个节点i你需要将bi改成ci. 这个bi值和ci值的范围是[0,1] 题解: 对于一个节点,如果它的bi==ci,那么我们就不用管它(因为你改变它的值,那么肯定之后还要花费成本再改回来,增加了成本).那么我们首先找出来一共有多少个节点bi!=ci ,然后总权值肯定是 num1*a1+num2*a2..…
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/problem/F Solution 设\(v_i\)表示第\(i\)个点的果子数,设\(b_i=v_i-\sum_{x\in son}v_x\),显然依题意要满足\(b_i\geqslant 0\). 根据差分的性质我们可以得到\(\sum b_i=x\). 假设我们硬点树上剩下了\(m\)个点,则…
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase Engl…
目录 A. Odd Selection B. Subsequence Hate C. Game On Leaves D. Guess The Maximums E. Tree Shuffling https://codeforces.com/contest/1363 A. Odd Selection 第一反应当然是分类讨论if到底.想了一下发现好像有点麻烦,正好n又不大所以for一下 枚举的方法,枚举原数组中取多少偶数(记为i),那么原数组中奇数就要取x-i个,只要判断x-i是否为奇数并且原数组…
D. The Bakery time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input output standard output Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven whic…
题目链接: http://codeforces.com/contest/675/problem/D 题意: 给你一系列点,叫你构造二叉搜索树,并且按输入顺序输出除根节点以外的所有节点的父亲. 题解: n有10^5,如果直接去建树,最会情况会O(n^2)t掉. 因此我们需要利用一些二叉搜索树的性质: 对于当前输入节点v,找出已经输入的最大的l和最小的r使得l<v<r. 由于输入v之前l和r中间是没有数的,所以l和r必定为祖先和后代的关系,如果不是的话,就会导致l和r中间还有数(l和r的公共祖先)…
https://codeforces.com/contest/1118/problem/F1 #include<bits/stdc++.h> using namespace std; int n; vector<int> color; vector<vector<int> > tree; ,blue=; ; pair<){ ); ); ;i<tree[v].size();i++){ int u=tree[v][i]; if(u!=p){//避免回…
D. Tree Construction 题目连接: http://www.codeforces.com/contest/675/problem/D Description During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so…
任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an undirected tree of nn vertices. Some vert…