http://codeforces.com/problemset/problem/739/B

dfs,记录距离前缀和,每次找到离最近的不符合的点。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std; int n,cnt = ,a[],b[],sta[],ans[] = {};
long long dis[];
vector<int> v[]; void dfs(int x,long long deep)
{
sta[++cnt] = x;
dis[x] = deep;
for(int i = ;i < v[x].size();i++)
{
int t = v[x][i];
dfs(t,dis[x]+b[t]);
ans[x] += ans[t]+;
}
int l = ,r = cnt-;
while(l < r)
{
int mid = (l+r+)/;
if(dis[x]-dis[sta[mid]] > a[x]) l = mid;
else r = mid-;
}
ans[sta[l]]--;
cnt--;
}
int main()
{
scanf("%d",&n);
for(int i = ;i <= n;i++) scanf("%d",&a[i]);
for(int i = ;i <= n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
v[x].push_back(i);
b[i] = y;
}
dfs(,);
for(int i = ;i <= n;i++) printf("%d ",ans[i]);
printf("\n");
return ;
}

Codeforces_739_B的更多相关文章

随机推荐

  1. 改变 windows ruby 的默认版本

    这个操作比较简单,就是调整 windows 环境变量 Path 子项的先后顺序. 原理就是:cmd 在运行命令时,先搜索当前目录,再按先后顺序搜索环境变量里边的目录. 因此,如果我们不想修改环境变量, ...

  2. centos7.3安装chrome

    Centos7安装chrome浏览器 1.配置yum源 在目录 /etc/yum.repos.d/ 下新建文件 google-chrome.repo cd /ect/yum.repos.d/ vim ...

  3. ipaclient 4.5.4 requires jinja2, which is not installed. rtslib-fb 2.1.63 has requirement pyudev>=0.16.1, but you'll have pyudev 0.15 which is incompatible. ipapython 4.5.4 has requirement dnspython>=

  4. Logger日志打印规范

    首先来看一下比较常用的Logger日志级别(部分未列出): error - 运行期错误日志记录,应该有专门的error日志文件.: warn - 警告信息,如程序调用了一个即将作废的接口,接口的不当使 ...

  5. react路由的跳转和传参

    1.路由的跳转 一.DOM跳转 在需要跳转的页面导入import {Link} from 'react-router-dom',在需要跳转的地方使用link标签的to属性进行跳转,路由配置文件中导出的 ...

  6. SpringBoot入门(一)

    1 简介 Spring Boot是快速搭建Spring工程的脚手架,简化配置与依赖关系(约定大于配置),让我们把精力集中在业务部分 2 简单入门事例 创建一个Hello World的Web工程 2.1 ...

  7. 在Winform界面使用自定义用户控件及TabelPanel和StackPanel布局控件

    在很多时候,我们做一些非常规化的界面的时候,往往需要创建一些用户控件,在其中绘制好一些基础的界面块,作为后续重复使用的一个单元,用户控件同时也可以封装处理一些简单的逻辑.在开发Winform各种类型项 ...

  8. 三、JVM之方法区

    一.什么式方法区 方法区,也称非堆(Non-Heap),又是一个被线程共享的内存区域.其中主要存储加载的类字节码.class/method/field等元数据对象.static-final常量.sta ...

  9. 世界上最流行的版本控制系统——Git

    版本控制系统,也就是VCS(Version Control System),可以说是程序员必备的工具.那么它到底是什么,有什么作用呢? 举个例子,如果你想查看你所开发的软件在一个月之前的模样,同时还想 ...

  10. numpy nan和inf

    一.nan和inf的简介 nan 不是一个数字 读取本地文件为flaot的时候,有缺失 inf(infinity): 无穷尽 inf: 正无穷 -inf: 负无穷 数据类型:float # 注意: 要 ...