#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<pair<int,int>> fruit(n);
for (int i =0; i < m;i ++) {
int v, d, w;
cin >> v >> d >> w;
v--;
fruit[v] = {d, w};
}
vector memo(n, vector(k+1, -1ll));
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 = 0ll;
if (fruit[i].first == day) res1 += fruit[i].second;
for (int e : child[i]) {
res1 += dp(dp, e, day);
}
if (day >= fruit[i].first && fruit[i].first)
res1 = max(res1, dp(dp, i, fruit[i].first-1));
return memo[i][day] = res1;
};
cout << dp(dp, 0, k) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
403 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
149 ms |
10804 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
414 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |