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