Submission #934274

#TimeUsernameProblemLanguageResultExecution timeMemory
934274tamir1Magic Tree (CEOI19_magictree)C++14
100 / 100
84 ms29332 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...