ARC083E. Bichrome Tree
A viable configuration of the given tree can be divided into two trees, each consists of vertices of the same color (if we compress edges and add a dummy root node when needed). Let's call them $T_B$ and $T_W$, respectively. Note that $T_B$ and $T_W$ are independent of each other with respect to satisfying the conditions. For each vertex $u$ in $T_A$, it must hold that the total weight of $u$'s proper descendants is no more than $X_u$, and in that case it is always possible make the total weight of vertices in subtree $u$ be $X_u$ by setting $u$'s weight appropriately. The same can be said for $T_B$. Ideally, we can configure the given tree such that in each subtree $u$, the total weight of vertices with a different color than $u$ are minimized.
Official editorial:

The hard part of this problem is to understand the highlighted sentence.
code
int main() {
int n;
scan(n);
vv g(n);
rng (i, 1, n) {
int p;
scan(p);
g[p - 1].pb(i);
}
vi x(n);
scan(x);
vi dp(n);
function dfs = [&](int u) {
vi f(x[u] + 1, INT_MAX);
f[0] = 0;
FOR (v, g[u]) {
dfs(v);
down (i, x[u], 0) {
if (f[i] != INT_MAX) {
int t = f[i];
f[i] = INT_MAX;
if (i + x[v] dfs(0);
println("POSSIBLE");
return 0;
}
I find this editorial in Chinese helpful.
ARC083E. Bichrome Tree的更多相关文章
- Bichrome Tree
Bichrome Tree 时间限制: 1 Sec 内存限制: 128 MB 题目描述 We have a tree with N vertices. Vertex 1 is the root of ...
- 【ARC083E】Bichrome Tree
Description 给一棵\(n\)个节点的树,和一个长度同样为\(n\)的非负整数序列\(x_i\). 请尝试对每个节点染黑或白两种颜色,并确定一个非负整数权值. 问是否存在一种方案 ...
- 【ARC083E】Bichrome Tree 树形dp
Description 有一颗N个节点的树,其中1号节点是整棵树的根节点,而对于第ii个点(2≤i≤N)(2≤i≤N),其父节点为PiPi 对于这棵树上每一个节点Snuke将会钦定一种颜色(黑或白), ...
- 【BZOJ】ARC083 E - Bichrome Tree
[算法]树型DP [题意]给定含n个点的树的形态,和n个数字Xv,要求给每个点赋予黑色或白色和权值,满足对于每个点v,子树v中和v同色的点的权值和等于Xv.n<=10^5 [题解]首先每个点的权 ...
- AtCoder Regular Contest 083 E - Bichrome Tree
题目传送门:https://arc083.contest.atcoder.jp/tasks/arc083_c 题目大意: 给定一棵树,你可以给这些点任意黑白染色,并且赋上权值,现给定一个序列\(X_i ...
- [AtCoder Regular Contest 083] Bichrome Tree
树形DP. 每个点有两个属性:黑色点的权值和,白色点权值和,一个知道另一个也一定知道. 因为只要子树的和它相等的点得权值和不超过x[u],u点的权值总能将其补齐. 设计状态f[u]表示以u为根的子树, ...
- 【AtCoder】ARC083
C - Sugar Water 计算一下可以达到水是多少,可以到达的糖是多少 枚举水,然后加最多能加的糖,是\(min(F - i *100,E * 100)\),计算密度,和前一个比较就行 #inc ...
- AtCoder Regular Contest 083
C - Sugar Water Time limit : 3sec / Memory limit : 256MB Score : 300 points Problem Statement Snuke ...
- AtCoder Regular Contest 093 E: Bichrome Spanning Tree(生成树)
Bichrome Spanning Tree 题意: 给出一个n个点,m条边的无向连通图,现在要给每条边染色,可以染成黑色或者白色. 现在要求在染色完毕后,找出一个至少包含一条黑边和一条白边的最小生成 ...
随机推荐
- Asia-Jakarata 2018
目录 Contest Info Solutions Problem A. Edit Distance Problem C. Smart Thief Problem D.Icy Land Problem ...
- bus error(总线错误)
转自 http://blog.csdn.net/todd911/article/details/8813321 在<C专家编程>中提到了总线错误bus error(core dumped) ...
- uiautomatorviewer真机使用报错Error obtaining UI hierarchy
Mac OS+Android真机 8.0在使用uiautomatorviewer获取界面时报Error obtaining UI hierarchy Reason: Error while obtai ...
- ImportError: No module named pytz
xxx@hostname:/opt/xx/cc$ python manage.py runserver Traceback (most recent call last): File , in < ...
- JS的十大排序算法
名词解释: n: 数据规模k:“桶”的个数In-place: 占用常数内存,不占用额外内存Out-place: 占用额外内存稳定性:排序后2个相等键值的顺序和排序之前它们的顺序相同 冒泡排序(Bub ...
- uiautomator2 wifi连接手机
[实施方法] 手机和电脑同时连接到同一个wifi上 1.开启远程adb #开启远端adb,这一步需要手机通过USB连接到电脑 adb tcpip 5555 #结果如下:restarting in TC ...
- Tensorflow使用训练好的模型进行测试,发现计算速度越来越慢
实验时要对多个NN模型进行对比,依次加载直到第8个模型时,发现运行速度明显变慢而且电脑开始卡顿,查看内存占用90+%. 原因:使用过的NN模型还会保存在内存,继续加载一方面使新模型加载特别特别慢,另一 ...
- arcgis python 把多个MXD批量导出一个PDF
# -*- coding: cp936 -*- import arcpy, os, string #Read input parameters from script tool mxdList = s ...
- CSS — 隐藏滚动条,依旧可以滚动
公司的系统,在PC端可以管理我们的公众号,在发布模块页面时有一个预览功能,呈现页面在手机端的样式. 做法很简单,一会就完成了,但是在预览内容过长时手机外框会有一个滚动条,影响美观,于是就想把它去掉,有 ...
- shell 變數
echo $? 上个命令的退出状态,或函数的返回值. ref: http://c.biancheng.net/cpp/view/2739.html