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的更多相关文章

  1. Bichrome Tree

    Bichrome Tree 时间限制: 1 Sec  内存限制: 128 MB 题目描述 We have a tree with N vertices. Vertex 1 is the root of ...

  2. 【ARC083E】Bichrome Tree

    Description ​ 给一棵\(n\)个节点的树,和一个长度同样为\(n\)的非负整数序列\(x_i\). ​ 请尝试对每个节点染黑或白两种颜色,并确定一个非负整数权值. ​ 问是否存在一种方案 ...

  3. 【ARC083E】Bichrome Tree 树形dp

    Description 有一颗N个节点的树,其中1号节点是整棵树的根节点,而对于第ii个点(2≤i≤N)(2≤i≤N),其父节点为PiPi 对于这棵树上每一个节点Snuke将会钦定一种颜色(黑或白), ...

  4. 【BZOJ】ARC083 E - Bichrome Tree

    [算法]树型DP [题意]给定含n个点的树的形态,和n个数字Xv,要求给每个点赋予黑色或白色和权值,满足对于每个点v,子树v中和v同色的点的权值和等于Xv.n<=10^5 [题解]首先每个点的权 ...

  5. AtCoder Regular Contest 083 E - Bichrome Tree

    题目传送门:https://arc083.contest.atcoder.jp/tasks/arc083_c 题目大意: 给定一棵树,你可以给这些点任意黑白染色,并且赋上权值,现给定一个序列\(X_i ...

  6. [AtCoder Regular Contest 083] Bichrome Tree

    树形DP. 每个点有两个属性:黑色点的权值和,白色点权值和,一个知道另一个也一定知道. 因为只要子树的和它相等的点得权值和不超过x[u],u点的权值总能将其补齐. 设计状态f[u]表示以u为根的子树, ...

  7. 【AtCoder】ARC083

    C - Sugar Water 计算一下可以达到水是多少,可以到达的糖是多少 枚举水,然后加最多能加的糖,是\(min(F - i *100,E * 100)\),计算密度,和前一个比较就行 #inc ...

  8. AtCoder Regular Contest 083

    C - Sugar Water Time limit : 3sec / Memory limit : 256MB Score : 300 points Problem Statement Snuke ...

  9. AtCoder Regular Contest 093 E: Bichrome Spanning Tree(生成树)

    Bichrome Spanning Tree 题意: 给出一个n个点,m条边的无向连通图,现在要给每条边染色,可以染成黑色或者白色. 现在要求在染色完毕后,找出一个至少包含一条黑边和一条白边的最小生成 ...

随机推荐

  1. Memcached 之在win10上的安装

    一.下载 http://static.runoob.com/download/memcached-win64-1.4.4-14.zip 二.安装 memcached <1.4.5 版本安装 1. ...

  2. spring boot处理跨域

    使用重写WebMvcConfigurer的方式 @Component public class WebMvcConfig extends WebMvcConfigurationSupport { @O ...

  3. 【java中的static关键字】

    文章转自:https://www.cnblogs.com/dolphin0520/p/3799052.html 一.static关键字的用途 在<Java编程思想>P86页有这样一段话: ...

  4. nginx配置不当引起的错误

    1.CRLF注入 1.1环境配置 apt install nginx vi /etc/nginx/sites-available/default location / { return 302 htt ...

  5. 重读APUE(15)-pthread_cond_wait与while循环

    即使pthead_cond_wait()和pthread_cond_timewait()没有错误返回,等待的条件也可能是假的:即使pthread_cond_timewait()返回了超时错误,关联的条 ...

  6. QMessageBox改变大小

    创建一个QMessageBox: QMessageBox msgBox(this);msgBox.setWindowTitle(tr("MailBox Location"));ms ...

  7. Python全国二级等级考试(2019)

    一.前言 2018年9月随着全国计算机等级考试科目中加入“二级Python”,也确立了Python在国内的地位,猪哥相信Python语言势必会像PS那般普及.不久的将来,谁会Python谁就能获得女神 ...

  8. mysql 调优 (转)

    原文:https://mp.weixin.qq.com/s__biz=MzI4NTA1MDEwNg==&mid=2650763421&idx=1&sn=2515421f09c1 ...

  9. scikit-learn机器学习(一)简单线性回归

    # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt ## 设置字符集,防止中文乱码 import ma ...

  10. 【作品集】UX作品集

    https://www.uisdc.com/10-inspiring-ux-portfolios http://jeya.io http://antonmircea.com/FinalUX.pdf h ...