This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
map<int,int> comp;
vector<pair<int,int>> fruit(n);
for (int i =0; i < m;i ++) {
ll v, d, w;
cin >> v >> d >> w;
v--;
comp[d] = 0;
fruit[v] = {d, w};
}
k = 0;
for (auto& mp: comp) mp.second = ++k;
for (auto& [d, w] : fruit)
d = comp[d];
auto dp = [&](auto& dp, int i)->vector<ll>{
vector<vector<ll>> dpc;
for (int e : child[i])
dpc.push_back(dp(dp, e));
vector<ll> res(k+1);
for (int day = 1; day <= k; day++) {
for (int j = 0; j < (int)dpc.size(); j++)
res[day] += dpc[j][day];
if (day == fruit[i].first)
res[day] += fruit[i].second;
}
int d = fruit[i].first;
if (d) {
res[d] = max(res[d], res[d-1]);
for (int i = d+1; i <= k; i++)
res[i] = max(res[i], res[d]);
}
return res;
};
cout << dp(dp, 0)[k] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |