【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 ...
随机推荐
- 【174】C#添加非默认字体
参考:C# WinForm程序安装字体或直接调用非注册字体 参考:百度知道 在Debug文件夹下面新建一个font的文件夹,然后将字体的文件复制到里面,使用的时候,直接调用字体文件! private ...
- Java多线程系列四——控制线程执行顺序
假设有线程1/线程2/线程3,线程3必须在线程1/线程2执行完成之后开始执行,有两种方式可实现 Thread类的join方法:使宿主线程阻塞指定时间或者直到寄生线程执行完毕 CountDownLatc ...
- Vue.js实战 5.5章 购物车
<!DOCTYPE html> <html lang="en"> <head> <title>购物车示例</title> ...
- NestedPreb
屌丝手动版 One of the things we’re sorely missing from Unity is nested prefabs. So we rolled this little ...
- 测试神器Swagger的相关使用
1.Swagger简介 swagger官网地址: https://swagger.io/ swagger官网文档介绍地址: https://swagger.io/about/ swagge是一个易 ...
- DotnetCore(1)尝鲜构建Web应用
在上篇文章中DotnetCore环境安装完成后,现在我们来尝试构建Web应用. 新建文件夹NetCoreWebDemo,并cd进入NetCoreWebDemo文件夹 同时Ctrl+shift按下快捷键 ...
- 如何上传文件到 github
1. 下载并安装 Git 2. 打开命令窗口:Git Bash Here 3. 在 github.coding 等上新建项目,并复制地址,如:https://git.coding.net/wangzh ...
- 基本的查询流【MSSQL】
4个DML(Data Manipulation Language)命令 SELECT INSERT UPDATE DELETE 查询语法有一个特有的固定顺序 SELECT - FROM - WHERE ...
- WordPress强制跳转https教程
在互联网火热的今天,安全问题显得越来越重要,为了用户信息安全,很多热门网站都启用了https 有小伙伴就问:我启用了https,为什么访问的时候显示的还是http呢? 其实,有时候并不是因为我们ssl ...
- HiveServer2后台运行
nohup hive --service hiveserver2 & 或者直接: nohup hiveserver2 &