【Codeforces 682C】Alyona and the Tree
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
设dis[v]表示v以上的点到达这个点的最大权值(肯定是它的祖先中的某个点到这个点)
类似于最大连续累加和
当往下走(x,y)这条边的时候,设其权值为w,以及到目前为止走过的最大权值和cur
如果cura[x]那么它以及它下面的所有节点都要删掉(因为要从叶子节点开始删)
如果dis[x]
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n,cnt;
int a[N+10];
vector<pair<int,int> > g[N+10];
void dfs(int x,long long now,int pre){
if (now>a[x]) return;
cnt++;
int len = g[x].size();
for (int i = 0;i < len;i++){
int y = g[x][i].first;
int w = g[x][i].second;
if (y==pre) continue;
dfs(y,max(1LL*0,now)+w,x);
}
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++) cin >> a[i];
for (int i = 2;i <= n;i++){
int x = i,y,w;
cin >> y >> w;
g[x].push_back(make_pair(y,w));
g[y].push_back(make_pair(x,w));
}
dfs(1,0,-1);
cout<<n-cnt<<endl;
return 0;
}
【Codeforces 682C】Alyona and the Tree的更多相关文章
- 【CodeForces - 682C】Alyona and the Tree(dfs)
Alyona and the Tree Descriptions 小灵决定节食,于是去森林里摘了些苹果.在那里,她意外地发现了一棵神奇的有根树,它的根在节点 1 上,每个节点和每条边上都有一个数字. ...
- 【30.36%】【codeforces 740D】Alyona and a tree
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【39.66%】【codeforces 740C】Alyona and mex
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【81.82%】【codeforces 740B】Alyona and flowers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【20.23%】【codeforces 740A】Alyona and copybooks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 764C】Timofey and a tree
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 514E】Darth Vader and Tree
[题目链接]:http://codeforces.com/problemset/problem/514/E [题意] 无限节点的树; 每个节点都有n个儿子节点; 且每个节点与其第i个节点的距离都是ai ...
- 【codeforces 777C】 Alyona and Spreadsheet
[题目链接]:http://codeforces.com/contest/777/problem/C [题意] 给你n行m列的矩阵: 然后给你k个询问[l,r]; 问你在第l到第r行,是否存在一个列, ...
- codeforces 682C C. Alyona and the Tree(dfs)
题目链接: C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input ...
随机推荐
- 什么是javascript闭包?
在我们开发中,也经常使用到闭包,但当有人问什么是闭包,就会可能说不上来.那就谈谈一些基本的: 一.理解闭包的概念, 简单说当function里嵌套function时,内部的function可以访问外部 ...
- JForum论坛添加UEditor文本编辑器
在使用JForum论坛中发现论坛自带的文本编辑器不好用,不能上传图片,样式编辑也很麻烦,就想着把这个文本编辑器替换掉,我这里选用的是百度的开源富文本编辑器UEditor 替换后的效果图 替换方法如下 ...
- CodeForces 731A Night at the Museum (水题)
题意:给定一个含26个英语字母的转盘,问你要得到目标字符串,至少要转多少次. 析:分别从顺时针和逆时针进行,取最小的即可. #pragma comment(linker, "/STACK:1 ...
- 矩阵取数游戏 2007年NOIP全国联赛提高组(dp+高精)
矩阵取数游戏 2007年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description [问题描述]帅帅经常跟 ...
- org.apache.poi.hssf.util.Region
从POI 3.18开始被Deprecated,在3.20版本中被移除了,所以3.20以前的都有 为了避免这个问题,用CellRangeAddress代替Region,其用法相同
- 回调函数,回调函数使用call
回调函数:一个函数b作为参数,给另外一个函数a使用.并且在执行a之后(注意不一定是执行完a),再去执行b这个函数. 上代码: function a(callback) { alert("我是 ...
- ssh&远程桌面连接工具finalshell
无意间发现的一款工具,有兴趣的可以看看点我进入官网 百度云盘 链接:https://pan.baidu.com/s/1wMuGav64e2zV91QznBkvag 密码:zpyb软件特点直接搬运的官方 ...
- C#基础 集合
//数组定义的时候 //需要定义数据类型 //需要定义初始长度 //int [] array = new int[5]; //int a = array.Length; //集合 //ArrayLis ...
- MSSQLSERVER_3176
本文档已存档,并且将不进行维护. MSSQLSERVER_3176 SQL Server 2014 SQL Server 2012 ...
- Ps 快捷键全解
一.工具箱(多种工具共用一个快捷键的可同时按[Shift]加此快捷键选取)矩形.椭圆选框工具 [M]移动工具 [V]套索.多边形套索.磁性套索 [L]魔棒工具 [W]裁剪工具 [C]切片工具.切片选择 ...