#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, k;
const int N = 100100;
int w[N];
int d[N];
int p[N];
int main() {
ios::sync_with_stdio(0),
cin.tie(0);
cin >> n >> m >> k;
for (int i = 2; i <= n; i++)
cin >> p[i];
for (int i = 0; i < m; i++) {
int u;
cin >> u;
cin >> d[u] >> w[u];
}
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));
for (int i = n; i >= 1; i--) {
ll val = dp[i][d[i]] + w[i];
for (int j = d[i]; j <= k; j++)
dp[i][j] = max(dp[i][j], val);
for (int j = 1; j <= k; j++)
dp[p[i]][j] += dp[i][j];
}
cout << dp[1][k] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
555 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8280 KB |
Output is correct |
2 |
Correct |
6 ms |
8288 KB |
Output is correct |
3 |
Correct |
5 ms |
8392 KB |
Output is correct |
4 |
Runtime error |
433 ms |
1048576 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
9052 KB |
Output is correct |
2 |
Correct |
28 ms |
9040 KB |
Output is correct |
3 |
Correct |
28 ms |
9012 KB |
Output is correct |
4 |
Correct |
26 ms |
8656 KB |
Output is correct |
5 |
Correct |
28 ms |
9056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
44 ms |
22608 KB |
Output is correct |
11 |
Correct |
29 ms |
14672 KB |
Output is correct |
12 |
Correct |
36 ms |
22616 KB |
Output is correct |
13 |
Correct |
31 ms |
22120 KB |
Output is correct |
14 |
Correct |
32 ms |
22608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
359 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
6 ms |
8280 KB |
Output is correct |
11 |
Correct |
6 ms |
8288 KB |
Output is correct |
12 |
Correct |
5 ms |
8392 KB |
Output is correct |
13 |
Runtime error |
433 ms |
1048576 KB |
Execution killed with signal 9 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Runtime error |
555 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |