【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 ...
随机推荐
- 移动端html touch事件
诸如智能手机和平板电脑一类的移动设备通常会有一(capacitive touch-sensitivescreen),以捕捉用户的手指所做的交互.随着移动网络的发展,其能够支持越来越复杂的应用,web开 ...
- bzoj 1642: [Usaco2007 Nov]Milking Time 挤奶时间【dp】
这不就是个n方dp吗--看了眼洛谷题解简直神仙打架 我全程没用到n-- 把休息时间并入产奶时间,注意"结束时间不挤奶",所以ei=ei+r-1,注意这个-1! 然后按r排序,设f[ ...
- python实现对excel数据进行修改/添加
import osimport xlrdfrom xlutils.copy import copydef base_dir(filename=None): return os.path.join(os ...
- [TYVJ1391]走廊泼水节
Description 话说,中中带领的OIER们打算举行一次冬季泼水节,当然这是要秘密进行的,绝对不可以让中中知道.不过中中可是老江湖了,当然很快就发现了我们的小阴谋,于是他准备好水枪迫不及待的想要 ...
- 数据传递--------博客-----------springMVC源码分析--RequestToViewNameTranslator请求到视图名称的转换
参考来源:http://blog.csdn.net/qq924862077/article/details/54286976?utm_source=gold_browser_extension Req ...
- 关于mybatis的xml文件中使用 >= 或者 <= 号报错的解决方案
当我们需要通过xml格式处理sql语句时,经常会用到< ,<=,>,>=等符号,但是很容易引起xml格式的错误,这样会导致后台将xml字符串转换为xml文档时报错,从而导致程序 ...
- 基于SOC方案的嵌入式开发-远程定时设备
Soc方案实现简单的定时开关灯 http://club.gizwits.com/forum.php?mod=viewthread&tid=7787&highlight=%E5%AE%9 ...
- mongo 3.4分片集群系列之五:详解平衡器
这个系列大致想跟大家分享以下篇章: 1.mongo 3.4分片集群系列之一:浅谈分片集群 2.mongo 3.4分片集群系列之二:搭建分片集群--哈希分片 3.mongo 3.4分片集群系列之三:搭建 ...
- JNDI链接SQLServer数据库步骤
1.配置context.xml文件 在我们的WebRoot目录下,就是和WEB-INF同级的目录下,新建一个META-INF的目录(假如不存在),在该目录下创建一个context.xml文件,并且在c ...
- Detectron-MaskRCnn:Mask判别和获取前向Mask的标签
对于FCN-SceneParse网络,最后卷积生成N个类别的maps,每个Map都得到图像所有点的单类概率.MaskRCNN的结构与FCN不相同. 参考三个文章: Detectron总结1:Blob的 ...