#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int mxn=1e5+5;
int d[mxn]{0};ll w[mxn];
map<int,ll>dp[mxn];
vector<int>g[mxn];
void dfs(int u){
for(auto v:g[u]){
dfs(v);
if(dp[v].size()>dp[u].size())swap(dp[u],dp[v]);
for(auto it:dp[v]){
if(dp[u].find(it.f)!=dp[u].end())dp[u][it.f]+=it.s;
else dp[u][it.f]=it.s;
}
}
if(d[u]==0)return;
if(dp[u].find(d[u])==dp[u].end())dp[u][d[u]]=w[u];
else dp[u][d[u]]+=w[u];
ll cur=w[u];
auto it = dp[u].upper_bound(d[u]);
vector<int>mem;
for(;it!=dp[u].end();it++){
if(cur>=it->s){
cur-=it->s;
dp[u][it->f]=0;mem.pb(u);
}
else {
dp[u][it->f]-=cur;
break;
}
}for(auto it : mem)dp[u].erase(it);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m,k;cin>>n>>m>>k;
for(int i=2;i<=n;i++){
int p;cin>>p;g[p].pb(i);
}
for(int i=1;i<=m;i++){
int v;cin>>v;cin>>d[v]>>w[v];
}dfs(1);ll ans=0;
for(auto it : dp[1])ans+=it.s;
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
7256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
17776 KB |
Output is correct |
2 |
Correct |
31 ms |
18608 KB |
Output is correct |
3 |
Correct |
104 ms |
34900 KB |
Output is correct |
4 |
Correct |
55 ms |
18384 KB |
Output is correct |
5 |
Correct |
68 ms |
20048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
7516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
13908 KB |
Output is correct |
2 |
Correct |
33 ms |
13140 KB |
Output is correct |
3 |
Correct |
34 ms |
17756 KB |
Output is correct |
4 |
Correct |
26 ms |
14464 KB |
Output is correct |
5 |
Correct |
34 ms |
25684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
7256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8024 KB |
Output is correct |
2 |
Correct |
14 ms |
10332 KB |
Output is correct |
3 |
Correct |
15 ms |
10448 KB |
Output is correct |
4 |
Correct |
16 ms |
10468 KB |
Output is correct |
5 |
Correct |
7 ms |
9188 KB |
Output is correct |
6 |
Correct |
15 ms |
12728 KB |
Output is correct |
7 |
Incorrect |
21 ms |
16732 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
7256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
7256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |