#include<bits/stdc++.h>
using namespace std;
#define N 7<<14
#define int long long
vector<int>adj[N];
map<int,int> dp[N];
int d[N],w[N];
void dfs(int n){
dp[n][0];
for(auto i:adj[n]){
dfs(i);
if(size(dp[n])<size(dp[i]))
swap(dp[n],dp[i]);
for(auto&[i,j]:dp[i])
dp[n][i]+=j;
dp[i].clear();
}
if(w[n]){
dp[n][d[n]]+=w[n];
auto it=dp[n].upper_bound(d[n]);
while(it!=dp[n].end()){
if(it->second<=w[n])
it=next(it),dp[n].erase(prev(it));
else {
it->second-=w[n];
break;
}
}
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n,m,k,Q;
cin>>n>>m>>k;
for(int i=2;i<=n;i++)
cin>>Q,adj[Q].push_back(i);
while(m--){
int a,b,c;
cin>>a>>b>>c;
d[a]=b,w[a]=c;
}
dfs(1);
int ans=0;
for(auto&[i,j]:dp[1])
ans+=j;
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
10072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
14928 KB |
Output is correct |
2 |
Correct |
35 ms |
21076 KB |
Output is correct |
3 |
Correct |
110 ms |
18516 KB |
Output is correct |
4 |
Correct |
54 ms |
16844 KB |
Output is correct |
5 |
Correct |
75 ms |
18516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
10328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
14292 KB |
Output is correct |
2 |
Correct |
64 ms |
14088 KB |
Output is correct |
3 |
Correct |
43 ms |
21888 KB |
Output is correct |
4 |
Correct |
29 ms |
13012 KB |
Output is correct |
5 |
Correct |
40 ms |
32596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
10072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
10844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
10072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
10072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |