#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int N, M, K, res = 0, u;
cin >> N >> M >> K;
vector<int> g[N];
int d[N] {}, w[N] {};
map<int, int> dp[N];
for(int i = 1; i < N; i++)
cin >> u, g[u-1].push_back(i);
while(M--)
cin >> u >> d[u-1] >> w[u-1];
for(u = N; --u >= 0; ) {
int h = 0;
for(int v : g[u])
if(size(dp[v]) > size(dp[h])) h = v;
dp[h].swap(dp[u]);
for(int v : g[u]) if(v != h)
for(auto &[i, j] : dp[v])
dp[u][i] += j;
dp[u][d[u]] += w[u];
auto f = dp[u].upper_bound(d[u]);
while(f != end(dp[u]) && (f->second -= w[u]) < 0)
w[u] = -f->second, f = dp[u].erase(f);
}
for(auto &[i, j] : dp[0]) res += j;
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
21008 KB |
Output is correct |
2 |
Correct |
34 ms |
14404 KB |
Output is correct |
3 |
Correct |
109 ms |
34804 KB |
Output is correct |
4 |
Correct |
61 ms |
19588 KB |
Output is correct |
5 |
Correct |
79 ms |
19412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
42 ms |
12028 KB |
Output is correct |
5 |
Correct |
61 ms |
15880 KB |
Output is correct |
6 |
Correct |
57 ms |
12060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
15140 KB |
Output is correct |
2 |
Correct |
69 ms |
14264 KB |
Output is correct |
3 |
Correct |
46 ms |
12664 KB |
Output is correct |
4 |
Correct |
40 ms |
15856 KB |
Output is correct |
5 |
Correct |
51 ms |
12004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
68 ms |
19148 KB |
Output is correct |
11 |
Correct |
64 ms |
17988 KB |
Output is correct |
12 |
Correct |
61 ms |
12620 KB |
Output is correct |
13 |
Correct |
36 ms |
15852 KB |
Output is correct |
14 |
Correct |
35 ms |
11980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3148 KB |
Output is correct |
2 |
Correct |
35 ms |
13976 KB |
Output is correct |
3 |
Correct |
31 ms |
14028 KB |
Output is correct |
4 |
Correct |
31 ms |
14156 KB |
Output is correct |
5 |
Correct |
20 ms |
15968 KB |
Output is correct |
6 |
Correct |
31 ms |
14340 KB |
Output is correct |
7 |
Correct |
27 ms |
12736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
42 ms |
12028 KB |
Output is correct |
14 |
Correct |
61 ms |
15880 KB |
Output is correct |
15 |
Correct |
57 ms |
12060 KB |
Output is correct |
16 |
Correct |
68 ms |
19148 KB |
Output is correct |
17 |
Correct |
64 ms |
17988 KB |
Output is correct |
18 |
Correct |
61 ms |
12620 KB |
Output is correct |
19 |
Correct |
36 ms |
15852 KB |
Output is correct |
20 |
Correct |
35 ms |
11980 KB |
Output is correct |
21 |
Correct |
17 ms |
5760 KB |
Output is correct |
22 |
Correct |
71 ms |
22288 KB |
Output is correct |
23 |
Correct |
85 ms |
26528 KB |
Output is correct |
24 |
Correct |
168 ms |
35864 KB |
Output is correct |
25 |
Correct |
64 ms |
19560 KB |
Output is correct |
26 |
Correct |
98 ms |
19176 KB |
Output is correct |
27 |
Correct |
70 ms |
15056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
56 ms |
21008 KB |
Output is correct |
11 |
Correct |
34 ms |
14404 KB |
Output is correct |
12 |
Correct |
109 ms |
34804 KB |
Output is correct |
13 |
Correct |
61 ms |
19588 KB |
Output is correct |
14 |
Correct |
79 ms |
19412 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
42 ms |
12028 KB |
Output is correct |
19 |
Correct |
61 ms |
15880 KB |
Output is correct |
20 |
Correct |
57 ms |
12060 KB |
Output is correct |
21 |
Correct |
61 ms |
15140 KB |
Output is correct |
22 |
Correct |
69 ms |
14264 KB |
Output is correct |
23 |
Correct |
46 ms |
12664 KB |
Output is correct |
24 |
Correct |
40 ms |
15856 KB |
Output is correct |
25 |
Correct |
51 ms |
12004 KB |
Output is correct |
26 |
Correct |
68 ms |
19148 KB |
Output is correct |
27 |
Correct |
64 ms |
17988 KB |
Output is correct |
28 |
Correct |
61 ms |
12620 KB |
Output is correct |
29 |
Correct |
36 ms |
15852 KB |
Output is correct |
30 |
Correct |
35 ms |
11980 KB |
Output is correct |
31 |
Correct |
6 ms |
3148 KB |
Output is correct |
32 |
Correct |
35 ms |
13976 KB |
Output is correct |
33 |
Correct |
31 ms |
14028 KB |
Output is correct |
34 |
Correct |
31 ms |
14156 KB |
Output is correct |
35 |
Correct |
20 ms |
15968 KB |
Output is correct |
36 |
Correct |
31 ms |
14340 KB |
Output is correct |
37 |
Correct |
27 ms |
12736 KB |
Output is correct |
38 |
Correct |
17 ms |
5760 KB |
Output is correct |
39 |
Correct |
71 ms |
22288 KB |
Output is correct |
40 |
Correct |
85 ms |
26528 KB |
Output is correct |
41 |
Correct |
168 ms |
35864 KB |
Output is correct |
42 |
Correct |
64 ms |
19560 KB |
Output is correct |
43 |
Correct |
98 ms |
19176 KB |
Output is correct |
44 |
Correct |
70 ms |
15056 KB |
Output is correct |
45 |
Correct |
21 ms |
5324 KB |
Output is correct |
46 |
Correct |
93 ms |
21432 KB |
Output is correct |
47 |
Correct |
87 ms |
24752 KB |
Output is correct |
48 |
Correct |
123 ms |
32324 KB |
Output is correct |
49 |
Correct |
68 ms |
19644 KB |
Output is correct |
50 |
Correct |
90 ms |
18516 KB |
Output is correct |
51 |
Correct |
90 ms |
14468 KB |
Output is correct |