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

【题意】

题意

【题解】

设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. PKUACM 2018 D chocolate【并查集+克鲁斯卡尔】

    传送:http://poj.openjudge.cn/practice/C18D/ 依然是课件截图 #include<iostream> #include<cstdio> #i ...

  2. P3256 [JLOI2013]赛车

    传送门 如果把速度看成斜率,起始位置看成截距,这就是一个水平可见直线了-- 不过这题里我实现方法借鉴了CQzhangyu大佬的,先按速度排序,然后维护一个单调栈,如果当前的人速度比栈顶大距离又比它远直 ...

  3. ACM_Appleman and Card Game(简单贪心)

    Appleman and Card Game Time Limit: 2000/1000ms (Java/Others) Problem Description: Appleman has n car ...

  4. 2、ipconfig命令

    该命令能够显示出正在使用的计算机的IP信息情况.这些信息包括IP地址.子网掩码.默认网关(连接本地计算机与Internet的计算机).通过IP地址可以进行扫描.远程管理.入侵检测等.ipconfig命 ...

  5. Java 8 (11) 新的日期和时间API

    在Java 1.0中,对日期和时间的支持只能依赖java.util.Date类.这个类只能以毫秒的精度表示时间.这个类还有很多糟糕的问题,比如年份的起始选择是1900年,月份的起始从0开始.这意味着你 ...

  6. Spring Boot (27) actuator服务监控与管理

    actuaotr是spring boot项目中非常强大的一个功能,有助于对应用程序进行监控和管理,通过restful api请求来监管.审计.收集应用的运行情况,针对微服务而言它是必不可少的一个环节. ...

  7. Android Bitmap转换WebP图片导致损坏的分析及解决方案

    背景 作为移动领域所力推的图片格式,WebP图片在商业领域证明了其应有的价值.基于其他格式的横向对比,其在压缩性能表现,及还原度极为优秀,节省大量的带宽开销.基于可观的效益比,团队早前已开始磋商将当前 ...

  8. ci框架中model简单的mysql操作

    <?php class SingerModel extends CI_Model { function SingerModel() { //会将数据库对象赋值给CI_Controller的db属 ...

  9. mysql 存储引擎学习

    现在我们常用的MySQL存储引擎主要是两种:InnoDB and MyISAM. 1.MyISAM 执行效率高 不支持事务 不支持外键 每个MyISAM在磁盘上存储成3个文件,其中文件名和表名都相同, ...

  10. glic,uClibc,EGLIBC 简要介绍

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...