Submission #723576

#TimeUsernameProblemLanguageResultExecution timeMemory
723576drdilyorMagic Tree (CEOI19_magictree)C++17
22 / 100
548 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, m, k; cin >> n >> m >> k; vector<vector<int>> child(n); vector par(n, -1); for (int i = 1; i < n; i++) { cin >> par[i]; child[--par[i]].push_back(i); } vector<vector<pair<int,int>>> fruit(n); for (int i = 0; i < m; i++) { int v, d, w; cin >> v >> d >> w; fruit[v-1].push_back({d, w}); } for (int i = 0; i < m; i++) sort(fruit[i].begin(), fruit[i].end()); auto chop = [&](auto& chop, int i, int day)->ll{ ll res = 0; for (auto [d, w] : fruit[i]) if (d == day) res += w; return res; }; vector memo(n, vector(k+1, -1)); auto dp = [&](auto& dp, int i, int day)->ll{ if (day == 0) return 0; if (memo[i][day] !=-1) return memo[i][day]; ll res1 = chop(chop, i, day); for (int e : child[i]) { res1 += dp(dp, e, day); } return memo[i][day] = max(res1, dp(dp, i, day-1)); }; cout << dp(dp, 0, k) << '\n'; }
#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...