B. Alyona and a tree
二分+dfs序+前缀和+瞎几把yy
#include "a.h" int n;
aLL a;
struct edge
{
int to, nx, w;
} e[N << ];
arr fi;
int ce = ;
aLL sum, ans;
aLL vec, up, down, res;
ll tot = ;
ll rs = ; inline void add(int u, int v, int w)
{
e[++ce] = edge{v, fi[u], w};
fi[u] = ce;
} void dfs(int x)
{
if (fi[x] == -)
{
rs = res[x];
rs += up[x], rs -= down[x];
ans[x] = rs;
return;
}
for (int i = fi[x]; i != -; i = e[i].nx)
{
int v = e[i].to, w = e[i].w;
sum[++tot] = sum[tot - ] + w;
int p = lower_bound(sum + , sum + + tot, sum[tot] - a[v]) - sum;
if (tot - >= p)
up[vec[tot - ]]++, down[vec[p - ]]++;
vec[tot] = v;
dfs(v);
tot--;
res[x] += rs;
rs = ;
}
rs = res[x];
rs += up[x], rs -= down[x];
ans[x] = rs;
} int main()
{
// file("test");
while (~scanf("%d", &n))
{
me(fi, -);
For(i, , n) sdf(a[i]);
For(i, , n)
{
int x, y;
sdf(x), sdf(y);
add(x, i, y);
}
vec[] = ;
sum[] = ;
dfs();
For(i, , n)
printf("%d ", ans[i]);
}
return ;
}
B. Alyona and a tree的更多相关文章
- Codeforces Round #381 (Div. 2)D. Alyona and a tree(树+二分+dfs)
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is ...
- codeforces 381 D Alyona and a tree(倍增)(前缀数组)
Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和
B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree ...
- Codeforces Round #381 (Div. 2) D. Alyona and a tree 树上二分+前缀和思想
题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsm ...
- CodeForces 682C Alyona and the Tree (树+dfs)
Alyona and the Tree 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/C Description Alyona ...
- Alyona and a tree
Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #358 (Div. 2) C. Alyona and the Tree 水题
C. Alyona and the Tree 题目连接: http://www.codeforces.com/contest/682/problem/C Description Alyona deci ...
- Codeforces Round #381 (Div. 2) D. Alyona and a tree dfs序+树状数组
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #358 (Div. 2) C. Alyona and the Tree dfs
C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...
- XJOI 3363 树4/ Codeforces 739B Alyona and a tree(树上差分+路径倍增)
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- Java 去除字符串中的空白字符
通过String的trim()方法只能去掉字符串两端的空格字符,但是对于\t \n等其它空白字符确不能去掉,因此需通过正则表达式,将其中匹配到的空白字符去掉,代码如下: protected Strin ...
- 【代码笔记】Web-Javascript-Javascript函数
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- 信息检索中的TF/IDF概念与算法的解释
https://blog.csdn.net/class_brick/article/details/79135909 概念 TF-IDF(term frequency–inverse document ...
- Android assets文件夹之位置放置和作用
Android 的assets文件夹的放置位置,Eclipse创建项目时就生成了的,Android Studio则不太一样,AS可以包含几种方式, 1:可以在build.gradle文件下配置,加如下 ...
- MySQL 5.7忘记root密码如何修改?
一直以来,MySQL的应用和学习环境都是MySQL 5.6和之前的版本,也没有去关注新版本MySQL 5.7的变化和新特性.今天帮人处理忘记root密码的时时候,发现以前的方法不奏效了.具体情况如下所 ...
- c# 采用datatable 快速导入数据至MSSQL的方法分享
转自:http://www.maomao365.com/?p=5613 摘要:下文讲述使用c#代码快速将dataTable导入至mssql数据库的方法 实现思路:需要将datatable调整为同目标表 ...
- 自动化测试基础篇--Selenium发送测试报告邮件
来自:https://www.cnblogs.com/sanzangTst/p/8377870.html 发邮件需要用到python两个模块,smtplib和email,这俩模块是python自带的, ...
- MySQL Host is blocked because of many connection errors 解决方法
应用日志提示错误:create connection error, url: jdbc:mysql://10.45.236.235:3306/db_wang?useUnicode=true&c ...
- c/c++ 线性栈
c/c++ 线性栈 线性栈 下面的代码实现了以下功能 函数 功能描述 push 压入 pop 弹出 show_list 打印 clear 移动top指针到栈底 destroy 释放所有内存空间 seq ...
- 集合抽象数据类型的C语言实现
链表是实现集合的一种理想的方式.将List以typedef的方式重命名为Set.这样做能保留链表简洁的特性,还能使集合具有了一些多态的特性. 使用这种方法的最大好处就是可以使用list_next来遍历 ...