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;
void dfs(ll a){
map<ll,ll> mp2;
for(ll i:v[a]){
dfs(i);
if(mp2.size()<mp.size()) swap(mp2,mp);
for(auto [p,q]:mp){
mp2[p]+=q;
}
}
if(day[a]>0){
mp2[day[a]]+=x[a];
while(true){
auto it=mp2.upper_bound(day[a]);
if(it==mp2.end()) break;
if(it->second<=x[a]){
x[a]-=it->second;
mp2.erase(it);
continue;
}
it->second-=x[a];
break;
}
}
swap(mp2,mp);
}
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(auto [a,b]:mp) ans+=b;
cout << ans;
}
Compilation message (stderr)
magictree.cpp: In function 'void dfs(long long int)':
magictree.cpp:12:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
12 | for(auto [p,q]:mp){
| ^
magictree.cpp: In function 'int main()':
magictree.cpp:47:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for(auto [a,b]:mp) ans+=b;
| ^
# | 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... |