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.

最新文章

  1. DBCC CheckDB遇到a database snapshot could not be created
  2. WdatePicker日期控件的用法
  3. C# 将文件转化成byte[]数组
  4. Hdu2544 最短路径 四种方法
  5. php吧字符串直接转换成数组处理
  6. deepdetect 用c++11写的机器学习caffe和XGBoost API 接口
  7. [CareerCup] 11.1 Merge Arrays 合并数组
  8. C#转义字符总结
  9. 【Python】Coding the Matrix:Week 5 Perspective Lab
  10. 一道看似简单的sql需求(转)
  11. js遍历数组对象和非数组对象
  12. php发送get、post请求获取内容的几种方法
  13. Json数组删除
  14. 关于Redis和Memcache的比较
  15. HTTP学习总结
  16. (后端)Mybatis实现批量删除操作(转)
  17. 一次linux服务器黑客入侵后处理
  18. MySQL优化(二) 优化诀窍
  19. 全网最详细的IDEA、Eclipse和MyEclipse之间于Java web项目发布到Tomcat上运行成功的对比事宜【博主强烈推荐】【适合普通的还是Maven方式创建的】(图文详解)
  20. python 变量名的规范

热门文章

  1. Codeforces Educational Codeforces Round 67
  2. 查询Linux下文件格式.
  3. 2019.6.28 校内测试 T3 【音乐会】道路千万条
  4. [题解] [SDOI2015] 序列统计
  5. make 和 make install 的区别
  6. Java并发指南2:深入理解Java内存模型JMM
  7. js中那些方法不改变原来的数组对象
  8. Linux系统下查找最近修改过的文件
  9. Python Docstring 风格和写法学习
  10. qt application logging