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

  1. int main() {
  2. int n;
  3. scan(n);
  4. vv g(n);
  5. rng (i, 1, n) {
  6. int p;
  7. scan(p);
  8. g[p - 1].pb(i);
  9. }
  10. vi x(n);
  11. scan(x);
  12. vi dp(n);
  13. function dfs = [&](int u) {
  14. vi f(x[u] + 1, INT_MAX);
  15. f[0] = 0;
  16. FOR (v, g[u]) {
  17. dfs(v);
  18. down (i, x[u], 0) {
  19. if (f[i] != INT_MAX) {
  20. int t = f[i];
  21. f[i] = INT_MAX;
  22. if (i + x[v] dfs(0);
  23. println("POSSIBLE");

  24. return 0;

  25. }

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. C语言学习笔记9-指针

    1.指针基础 NULL为预处理器变量,是从C继承下来的,该变量在cstdlib头文件中定义 2.指针函数与函数指针 3.指针数组与数组指针 4.

  2. docker pull 报错Get https://xxx.xxx.xxx.xxx:5000/v1/_ping: http: server gave HTTP response

    解决方法: vim /etc/docker/daemon.json { "insecure-registries":["xxx.xxx.xxx.xxx:5000" ...

  3. Codeforces 1276D/1259G Tree Elimination (树形DP)

    题目链接 http://codeforces.com/contest/1276/problem/D 题解 我什么DP都不会做,吃枣药丸-- 设\(f_{u,j}\)表示\(u\)子树内,\(j=0\) ...

  4. flex的圣杯布局记录 (flex : 0 0 80px)

  5. Linux rpm 安装MySQL

    1 检查是否存在旧版本mysql (1) mysql 执行命令:rpm -qa|grep mysql,若存在旧mysql,删除查询到的旧mysql,执行: rpm -e --nodeps XXXX  ...

  6. https://uwsgi-docs.readthedocs.io/en/latest/Async.html

    Beware! Async modes will not speed up your app, they are aimed at improving concurrency. Do not expe ...

  7. 在Win7下玩PC游戏发生类似d3d9x_43.dll找不到的情况

    由于d3d9x属于DirectX9.0c扩展,默认不会随系统安装.因此要快速修复这个问题可以去微软官网下载D3D驱动补丁. http://www.microsoft.com/zh-cn/downloa ...

  8. Scrapy - 小说爬虫

    实例解析 - 小说爬虫 页面分析 共有三级页面 一级页面 大目录 二级页面 章节目录 三级界面 章节内容 爬取准备 一级界面 http://www.daomubiji.com/ 二级页面xpath 直 ...

  9. 11Flutter页面布局 Stack层叠组件 Stack与Align Stack与Positioned实现定位布局

    /* Flutter 页面布局 Stack层叠组件: Stack与Align Stack与Positioned实现定位布局: Flutter Stack组件: Stack表示堆得意思,我们可以用Sta ...

  10. windows和Linux下定时启动或关闭服务

    http://blog.csdn.net/clare504/article/details/17410643 1.Windows下的定时启动程序可以采用系统的计划和任务,定时启动服务可以在计划任务中添 ...