Submission #413472

#TimeUsernameProblemLanguageResultExecution timeMemory
413472nicolaalexandraMagic Tree (CEOI19_magictree)C++14
6 / 100
173 ms13788 KiB
#include <bits/stdc++.h> #define DIM 1010 using namespace std; int dp[DIM][DIM],v[DIM],cost[DIM]; vector <int> L[DIM]; int n,m,k,i,j,x,y,w,d; void dfs (int nod, int tata){ int ok = 0; for (auto vecin : L[nod]) if (vecin != tata){ ok = 1; dfs (vecin,nod); } if (!ok){ if (v[nod]){ for (int i=v[nod];i<=k;i++) dp[nod][i] = cost[nod]; } } else { for (auto vecin : L[nod]){ if (vecin == tata) continue; for (int i=1;i<=k;i++) dp[nod][i] += dp[vecin][i]; } if (v[nod]){ int val = cost[nod]; for (auto vecin : L[nod]) if (vecin != tata) val += dp[vecin][v[nod]]; dp[nod][v[nod]] = max (dp[nod][v[nod]],val); } for (int i=1;i<=k;i++) dp[nod][i] = max (dp[nod][i],dp[nod][i-1]); } } int main (){ //ifstream cin ("date.in"); //ofstream cout ("date.out"); cin>>n>>m>>k; for (i=2;i<=n;i++){ cin>>x; L[x].push_back(i); L[i].push_back(x); } for (i=1;i<=m;i++){ cin>>x>>d>>w; v[x] = d, cost[x] = w; } dfs (1,0); int sol = 0; for (i=1;i<=k;i++) sol = max (sol,dp[1][i]); cout<<sol; return 0; }
#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...