제출 #934264

#제출 시각아이디문제언어결과실행 시간메모리
934264tamir1Magic Tree (CEOI19_magictree)C++14
100 / 100
116 ms36688 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[100005]; map<ll,ll> ::iterator it; void dfs(ll a){ 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 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...