#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
const ll maxn=1e5+5;
const ll inf=1e15;
vector<ll> adj[maxn];
set<ii> s[maxn];
ii arr[maxn];
void dfs(ll x){
for (auto u:adj[x]){
dfs(u);
if (s[u].size()>s[x].size()) swap(s[u],s[x]);
for (auto [a,b]:s[u]) s[x].emplace(a,b);
}
ll pos,cnt;
tie(pos,cnt)=arr[x];
while (cnt){
ll p,c;
if (s[x].lower_bound(make_pair(pos,-1))==s[x].end()) break;
tie(p,c)=*s[x].lower_bound(make_pair(pos,-1));
if (cnt>=c){
cnt-=c;
s[x].erase(make_pair(p,c));
} else{
s[x].erase(make_pair(p,c));
c-=cnt;
cnt=0;
s[x].emplace(p,c);
}
}
s[x].emplace(arr[x]);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,k,m,a,b,c;
cin>>n>>k>>m;
for (int i=2;i<=n;i++){
cin>>a;
adj[a].emplace_back(i);
}
for (int i=1;i<=k;i++){
cin>>a>>b>>c; //pos, time, value
arr[a]={b,c};
}
dfs(1);
ll ans=0;
for (auto [u,v]:s[1]) ans+=v;
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
22428 KB |
Output is correct |
2 |
Correct |
40 ms |
21840 KB |
Output is correct |
3 |
Correct |
104 ms |
41044 KB |
Output is correct |
4 |
Correct |
62 ms |
23760 KB |
Output is correct |
5 |
Correct |
88 ms |
25424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
9052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
96 ms |
31176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10328 KB |
Output is correct |
2 |
Correct |
24 ms |
15052 KB |
Output is correct |
3 |
Correct |
33 ms |
14580 KB |
Output is correct |
4 |
Correct |
23 ms |
14864 KB |
Output is correct |
5 |
Correct |
15 ms |
16596 KB |
Output is correct |
6 |
Correct |
29 ms |
18232 KB |
Output is correct |
7 |
Correct |
24 ms |
19624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |