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条边的无向连通图,现在要给每条边染色,可以染成黑色或者白色. 现在要求在染色完毕后,找出一个至少包含一条黑边和一条白边的最小生成 ...
随机推荐
- Hdu Can you find it?(二分答案)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others) P ...
- Java集合总结(二):Map和Set
集合类的架构图: HashMap 内部维护一个链表数组做哈希表,默认大小为16,最大值可以为2^30,默认负载因子0.75. 可以通过构造方法指定初始大小和负载因子,当键值对个数大于等于临界值thre ...
- 使用zabbix-proxy
事情背景: vt上两个vps,只提供ipv6.(因为便宜嘛).而我的zabbix服务器在腾讯云.它丫的没有ipv6. 那么我没法监控它们了呀... 这咋个行呢? 想办法... 我还有另外的vps 可以 ...
- k8s/Kubernetes常用组件Helm的部署
Helm的安装 1.Helm的基本概念 Helm是Kubernetes的一个包管理工具,用来简化Kubernetes应用的部署和管理.可以把Helm比作CentOS的yum工具. Helm有如下几个基 ...
- python 小游戏 “外星飞船入侵”
Project Title 项目名称 “外星飞船入侵”, git地址:https://github.com/lilinyu861/Alien-Invasion 效果图: 参考: https://blo ...
- Echarts——关系图(人民的名义为例,简化)源码
参考博文:https://www.cnblogs.com/emrys5/p/echart-relationship-map.html <!DOCTYPE html> <html> ...
- Python学习日记(三)——Python基本数据类型(运算符、int、str、tuple、dict、range)
运算符 1.算数运算 2.比较运算 3.赋值运算 4.逻辑运算 5.成员运算 基本数据类型 1.数字 int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2 ...
- iOS开发 Error: CGImageProviderCreate: invalid image provider size
一般可拉伸的图片(俗称点9图片)会放到images.xcassets目录里,然后对图片进行Slicing,但是当对一张图片进行slicing的left和right都是0的话,在iOS7.0上运行会出现 ...
- nginx 配置简单反向代理
假设端口号是 3000 server { listen ; server_name your.domain; location / { proxy_pass http://127.0.0.1:3000 ...
- 关系型数据库的树形结构查询(Oracle、Postgres)
Oracle : start with… connect by 的用法.语法:select * from table [where 条件1] connect by[条件2] start with[条件 ...