This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,k,i,day[100005],x[100005],node,d,w,p[100005],ans;
vector<ll> v[100005];
map<ll,ll> mp[100005];
map<ll,ll> ::iterator it;
void dfs(ll a){
map<ll,ll> ::iterator it;
for(ll i:v[a]){
dfs(i);
if(mp[a].size()<mp[i].size()) swap(mp[a],mp[i]);
for(it=mp[i].begin();it!=mp[i].end();it++){
mp[a][it->first]+=it->second;
}
}
if(day[a]>0){
mp[a][day[a]]+=x[a];
while(true){
it=mp[a].upper_bound(day[a]);
if(it==mp[a].end()) break;
if(it->second<=x[a]){
x[a]-=it->second;
mp[a].erase(it);
continue;
}
it->second-=x[a];
break;
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for(i=2;i<=n;i++){
cin >> p[i];
v[p[i]].push_back(i);
}
for(i=1;i<=m;i++){
cin >> node >> d >> w;
day[node]=d;
x[node]=w;
}
dfs(1);
for(it=mp[1].begin();it!=mp[1].end();it++) ans+=it->second;
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |