二分+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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. CodeForces 682C Alyona and the Tree (树+dfs)

    Alyona and the Tree 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/C Description Alyona ...

  6. Alyona and a tree

    Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. 归并排序(MergeSort)和快速排序(QuickSort)的一些总结问题

    归并排序(MergeSort)和快速排序(QuickSort)都是用了分治算法思想. 所谓分治算法,顾名思义,就是分而治之,就是将原问题分割成同等结构的子问题,之后将子问题逐一解决后,原问题也就得到了 ...

  2. 切换横竖屏的时候Activity的生命周期变化情况

    关于这个,有个博客说得比较清楚:http://blog.csdn.net/wulianghuan/article/details/8603982,直接给出链接,哈哈哈.

  3. How do I install Daydream on my phone?

    Google's philosophy with their newest VR platform is simple. In order to offer the best possible exp ...

  4. Android Service、IntentService,Service和组件间通信

    Service组件 Service 和Activity 一样同为Android 的四大组件之一,并且他们都有各自的生命周期,要想掌握Service 的用法,那就要了解Service 的生命周期有哪些方 ...

  5. <自动化测试方案_4>第四章、选型标准

    第四章.选型标准 1,免费 2,工具可维护.可扩展 3,支持团队工作

  6. verilog实现红黄蓝三秒灯

    代码如下 test.v文件 led.v文件 module test(); wire led_r,led_g,led_b; ; clk <= ~clk; led c1 ( .clk(clk), . ...

  7. (网页)websocket后台调用Service层

    百度论坛里面有很多好的方法,借鉴. 重点:因为项目是StringBoot所以我用的是下面的方法很好使: Service.... service = (Service....) ContextLoade ...

  8. Django-404错误处理

    404错误是用户输入错误的URL,在 URLconf 中匹配不到相应的URL而抛出的异常 如下图: 为了给用户提供一个友好的访问,需要配置404错误页面 1.在 templates 目录下新建 404 ...

  9. myBase7.0破解

    永久性破解 Mybase7Pro破解版下载:链接:https://pan.baidu.com/s/1ezb8bSqI0OPZnVgx-snA_Q  提取码:n72t 1.下载后安装 myBase-De ...

  10. ubuntu 环境下编译 hadoop 2.6.0的简单方法

    由于服务器一般都64位系统, hadoop网站的release版本32位native库不能运行,所以需要自己在编译一下.以下是我采用的一个编译的过程,比较简单,不用下载各种版本及环境配置,通过命令就能 ...