BZOJ 3011: [Usaco2012 Dec]Running Away From the Barn( dfs序 + 主席树 )

子树操作, dfs序即可.然后计算<=L就直接在可持久化线段树上查询
-------------------------------------------------------------------
-------------------------------------------------------------------
3011: [Usaco2012 Dec]Running Away From the Barn
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 136 Solved: 74
[Submit][Status][Discuss]
Description
It's milking time at Farmer John's farm, but the cows have all run away! Farmer John needs to round them all up, and needs your help in the search. FJ's farm is a series of N (1 <= N <= 200,000) pastures numbered 1...N connected by N - 1 bidirectional paths. The barn is located at pasture 1, and it is possible to reach any pasture from the barn. FJ's cows were in their pastures this morning, but who knows where they ran to by now. FJ does know that the cows only run away from the barn, and they are too lazy to run a distance of more than L. For every pasture, FJ wants to know how many different pastures cows starting in that pasture could have ended up in. Note: 64-bit integers (int64 in Pascal, long long in C/C++ and long in Java) are needed to store the distance values.
Input
* Line 1: 2 integers, N and L (1 <= N <= 200,000, 1 <= L <= 10^18)
* Lines 2..N: The ith line contains two integers p_i and l_i. p_i (1 <= p_i < i) is the first pasture on the shortest path between pasture i and the barn, and l_i (1 <= l_i <= 10^12) is the length of that path.
Output
* Lines 1..N: One number per line, the number on line i is the number pastures that can be reached from pasture i by taking roads that lead strictly farther away from the barn (pasture 1) whose total length does not exceed L.
Sample Input
1 4
2 3
1 5
Sample Output
2
1
1
OUTPUT DETAILS: Cows from pasture 1 can hide at pastures 1, 2, and 4. Cows from pasture 2 can hide at pastures 2 and 3. Pasture 3 and 4 are as far from the barn as possible, and the cows can hide there.
HINT
Source
BZOJ 3011: [Usaco2012 Dec]Running Away From the Barn( dfs序 + 主席树 )的更多相关文章
- BZOJ_3011_[Usaco2012 Dec]Running Away From the Barn _可并堆
BZOJ_3011_[Usaco2012 Dec]Running Away From the Barn _可并堆 Description 给出以1号点为根的一棵有根树,问每个点的子树中与它距离小于l的 ...
- 【BZOJ3011】[Usaco2012 Dec]Running Away From the Barn 可并堆
[BZOJ3011][Usaco2012 Dec]Running Away From the Barn Description It's milking time at Farmer John's f ...
- dfs序+主席树 或者 树链剖分+主席树(没写) 或者 线段树套线段树 或者 线段树套splay 或者 线段树套树状数组 bzoj 4448
4448: [Scoi2015]情报传递 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 588 Solved: 308[Submit][Status ...
- BZOJ 3439: Kpm的MC密码 (trie+dfs序主席树)
题意 略 分析 把串倒过来插进trietrietrie上, 那么一个串的kpmkpmkpm串就是这个串在trietrietrie上对应的结点的子树下面的所有字符串. 那么像 BZOJ 3551/354 ...
- [BZOJ3011][Usaco2012 Dec]Running Away From the Barn
题意 给出一棵以1为根节点树,求每个节点的子树中到该节点距离<=l的节点的个数 题解 方法1:倍增+差分数组 首先可以很容易的转化问题,考虑每个节点对哪些节点有贡献 即每次对于一个节点,找到其第 ...
- bzoj3011 [Usaco2012 Dec]Running Away From the Barn 左偏树
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=3011 题解 复习一下左偏树板子. 看完题目就知道是左偏树了. 结果这个板子还调了好久. 大概已 ...
- [Usaco2012 Dec]Running Away From the Barn
题目描述 给出以1号点为根的一棵有根树,问每个点的子树中与它距离小于等于l的点有多少个. 输入格式 Line 1: 2 integers, N and L (1 <= N <= 200,0 ...
- bzoj 3439 Kpm的MC密码(Trie+dfs序+主席树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3439 [题意] 给定若干串,问一个串的作为其后缀的给定串集合中的第k小. [思路] 如 ...
- BZOJ 3439: Kpm的MC密码( trie + DFS序 + 主席树 )
把串倒过来插进trie上, 那么一个串的kpm串就是在以这个串最后一个为根的子树, 子树k大值的经典问题用dfs序+可持久化线段树就可以O(NlogN)解决 --------------------- ...
随机推荐
- ofbiz学习笔记
最新稳定版apache-ofbiz-13.07.02 最新源码ofbiz-release14.12 ant load-demo 载入演示样例数据 ant load-seed 仅仅载入种子数据 ant ...
- js动画学习(三)
五.多物体变宽 这里面要注意由于物体变多了,需要给每个物体各配备一个定时器,否则如果只有一个定时器的话,当鼠标在不同物体之间快速滑动时,不同的物体就会出现争抢的现象.所以timer前要加obj. fu ...
- jQuery扩展extend一
把这个扩展写在这里,以后要是忘了可以回头查看. (function(j) {// 这里的j是一个形参,表示传入的jQuery对象,j可以任意填写 j.extend({// 相当于给jQuery对象加上 ...
- jQuery.form 中的 ajaxForm() 和 ajaxSubmit()
官方例子 http://malsup.com/jquery/form/#ajaxForm官方API http://malsup.com/jquery/form/#api中文API http: ...
- ASP.NET MVC3 Razor视图引擎-基础语法
I:ASP.NET MVC3在Visual Studio 2010中的变化 在VS2010中新建一个MVC3项目可以看出与以往的MVC2发生了很明显的变化. 1.ASP.NET MVC3必要的运行环境 ...
- Qt 技巧:去除对话框边框 + 设置窗口可移动和透明
1.去除对话框标题栏和边框 在构造函数里设置: this->setWindowFlags(Qt::FramelessWindowHint); Qt::Dialog (按照对话框的形 ...
- MyEclipse2014不支持jre1.8吗
myeclipse 2015才支持了java 8 也可以用Eclipse Kepler加插件的形式来支持java 8
- 转:.Net程序员学习Linux最简单的方法
有很多关于Linux的书籍,博客.大多数都会比较“粗暴“的将一大堆的命令塞给读者,从而使很多.NET程序员望而却步.未入其门就路过了. 所以我设想用一种更为平滑的学习方式, 就是在学习命令时,先用纯语 ...
- html = data.decode('gbk').encode('utf-8')
html = data.decode('gbk').encode('utf-8')此处encode编码要与html文件内charset=utf-8的格式一致,如果不一致,浏览器打开乱码,文本编辑器正常 ...
- android 调出显示标题栏(title bar)
无法同时继承fragmentactivity和actionbaractivity 解决方法 import android.support.v7.app.ActionBarActivity; 将exte ...