【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

设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的更多相关文章

  1. 【CodeForces - 682C】Alyona and the Tree(dfs)

    Alyona and the Tree Descriptions 小灵决定节食,于是去森林里摘了些苹果.在那里,她意外地发现了一棵神奇的有根树,它的根在节点 1 上,每个节点和每条边上都有一个数字. ...

  2. 【30.36%】【codeforces 740D】Alyona and a tree

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【39.66%】【codeforces 740C】Alyona and mex

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【20.23%】【codeforces 740A】Alyona and copybooks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【codeforces 764C】Timofey and a tree

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 514E】Darth Vader and Tree

    [题目链接]:http://codeforces.com/problemset/problem/514/E [题意] 无限节点的树; 每个节点都有n个儿子节点; 且每个节点与其第i个节点的距离都是ai ...

  8. 【codeforces 777C】 Alyona and Spreadsheet

    [题目链接]:http://codeforces.com/contest/777/problem/C [题意] 给你n行m列的矩阵: 然后给你k个询问[l,r]; 问你在第l到第r行,是否存在一个列, ...

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

随机推荐

  1. 【废弃中】【WIP】JavaScript 数组

    创建: 2018/01/22 更新: 2018/05/20 把此博文加入[javascript]分类, 原来忘记了 废弃: 2019/02/19 重构此篇.原文归入废弃  增加[废弃中]标签与总体任务 ...

  2. Extjs grid禁用头部点击三角下拉菜单

    表格头部的三角在点击的时候禁止出现下拉菜单,给每一列添加属性menuDisabled:true xtype:'grid', enableColumnResize:false, columns:[ {t ...

  3. python中socket编程

    一.网络协议 客户端/服务器架构 1.硬件C/S架构(打印机) 2.软件C/S架构(互联网中处处是C/S架构):B/S架构也是C/S架构的一种,B/S是浏览器/服务器 C/S架构与socket的关系: ...

  4. 389 Find the Difference 找不同

    给定两个字符串 s 和 t,它们只包含小写字母.字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母.请找出在 t 中被添加的字母.示例:输入:s = "abcd"t = ...

  5. C#知识点-枚举器和迭代器

    一.几个基本概念的理解 问题一:为什么数组可以使用foreach输出各元素 答:数组是可枚举类型,它实现了一个枚举器(enumerator)对象:枚举器知道各元素的次序并跟踪它们的位置,然后返回请求的 ...

  6. 继承static的注意点

    继承static的注意点 singleton模式会使用 <?php class Auth { protected static $_instance = null; /** * 单用例入口 * ...

  7. 关于Python多线程condition变量的应用

    ''' 所谓条件变量,即这种机制是在满足了特定的条件后,线程才可以访问相关的数据. 它使用Condition类来完成,由于它也可以像锁机制那样用,所以它也有acquire方法和release方法,而且 ...

  8. 伪装IP进行投票

    伪装IP投票说明 1,目的 在访问网页链接进行投票时,网站往往对同一个IP的投票次数进行了限制,无法连续重复投票.为此可以使用“火狐浏览器+IP修改插件”,通过人为设置浏览器IP,绕过网站IP检查,可 ...

  9. PHP——基本使用(一)

    Apache安装与配置 install 下载地址:https://www.apachelounge.com/download/,选择2.4.33版本64位 将程序解压到一个英文目录下,以管理身份打开c ...

  10. Java 基础入门随笔(11) JavaSE版——继承、覆盖、抽象类

    1.面向对象的特征二:继承 定义: 指一个对象直接使用另一对象的属性和方法. 继承好处: 1.提供代码的复用性. 2.让类与类直接产生了关系,给第三个特征多态提供了前提. java中支持单继承.不直接 ...