Submission #723660

#TimeUsernameProblemLanguageResultExecution timeMemory
723660Erkinoff_MohammedMagic Tree (CEOI19_magictree)C++14
0 / 100
2073 ms24480 KiB
#include "bits/stdc++.h" using namespace std; #define INF 2000000000 #define INFLL 3000000000000000000LL #define ll long long int n,m,k; vector<int>childs[100000]; vector<long long> fr(100000); vector<int> dy(100000); vector<long long> dfs(int v){ vector<long long>cur(k); for(int i:childs[v]){ vector<long long>vec=dfs(i); for(int j=0;j<k;j++){ cur[j]+=vec[j]; } } if(fr[v]>0){ int sum=0; for(int i=dy[v]+1;i<k;i++){ sum+=cur[i]; } if(sum<fr[v]){ cur[dy[v]]+=fr[v]; for(int i=dy[v]+1;i<k;i++){ cur[i]=0; } } } return cur; } int main() { cin.tie(0)->sync_with_stdio(0); cin>>n>>m>>k; int par[n]; par[0]=-1; for(int i=1;i<n;i++){ cin>>par[i]; par[i]--; childs[par[i]].push_back(i); fr[i]=0; dy[i]=0; } for(int i=0;i<m;i++){ int v,d,w; cin>>v>>d>>w; v--; d--; fr[v]=w; dy[v]=d; } int out=0; vector<long long>vec=dfs(0); for(int i:vec)out+=i; cout<<out; }
#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...