#include <iostream>
#include <queue>
#define ll long long
using namespace std;
vector <ll> adj[200000];
ll n, f, x, A[200000], H[200000], C[200000], in[200000];
ll dp[200000];
ll dfs(ll u, ll w) {
ll ret = 0, s = 0;
if (w <= H[u]) ret = max(ret, dp[u]);
for (auto v : adj[u]) {
s += dfs(v, w);
}
return max(ret, s);
}
void solve(ll u) {
for (auto v : adj[u]) {
solve(v);
}
dp[u] = C[u];
for (auto v : adj[u]) {
dp[u] += dfs(v, H[u]);
}
}
int main() {
cin >> n;
for (int i=0; i<n; ++i) {
cin >> A[i] >> H[i] >> C[i];
f += C[i];
--A[i];
if (i != A[i]) adj[A[i]].push_back(i);
}
solve(0);
cout << f-dfs(0, 0) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10732 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
5 ms |
10852 KB |
Output is correct |
6 |
Correct |
6 ms |
10844 KB |
Output is correct |
7 |
Correct |
5 ms |
10844 KB |
Output is correct |
8 |
Correct |
5 ms |
10852 KB |
Output is correct |
9 |
Correct |
5 ms |
10844 KB |
Output is correct |
10 |
Correct |
6 ms |
10844 KB |
Output is correct |
11 |
Correct |
7 ms |
10984 KB |
Output is correct |
12 |
Correct |
86 ms |
11256 KB |
Output is correct |
13 |
Correct |
77 ms |
11240 KB |
Output is correct |
14 |
Correct |
42 ms |
11140 KB |
Output is correct |
15 |
Correct |
43 ms |
11096 KB |
Output is correct |
16 |
Correct |
5 ms |
10840 KB |
Output is correct |
17 |
Correct |
5 ms |
10844 KB |
Output is correct |
18 |
Correct |
6 ms |
10840 KB |
Output is correct |
19 |
Correct |
38 ms |
10840 KB |
Output is correct |
20 |
Correct |
41 ms |
10840 KB |
Output is correct |
21 |
Correct |
35 ms |
10924 KB |
Output is correct |
22 |
Correct |
5 ms |
10844 KB |
Output is correct |
23 |
Correct |
5 ms |
10844 KB |
Output is correct |
24 |
Correct |
54 ms |
11124 KB |
Output is correct |
25 |
Correct |
54 ms |
11352 KB |
Output is correct |
26 |
Correct |
68 ms |
11244 KB |
Output is correct |
27 |
Correct |
22 ms |
10840 KB |
Output is correct |
28 |
Correct |
42 ms |
11352 KB |
Output is correct |
29 |
Correct |
56 ms |
11096 KB |
Output is correct |
30 |
Correct |
36 ms |
11096 KB |
Output is correct |
31 |
Correct |
36 ms |
11100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10732 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
5 ms |
10852 KB |
Output is correct |
6 |
Correct |
6 ms |
10844 KB |
Output is correct |
7 |
Correct |
5 ms |
10844 KB |
Output is correct |
8 |
Correct |
5 ms |
10852 KB |
Output is correct |
9 |
Correct |
5 ms |
10844 KB |
Output is correct |
10 |
Correct |
6 ms |
10844 KB |
Output is correct |
11 |
Correct |
7 ms |
10984 KB |
Output is correct |
12 |
Correct |
86 ms |
11256 KB |
Output is correct |
13 |
Correct |
77 ms |
11240 KB |
Output is correct |
14 |
Correct |
42 ms |
11140 KB |
Output is correct |
15 |
Correct |
43 ms |
11096 KB |
Output is correct |
16 |
Correct |
5 ms |
10840 KB |
Output is correct |
17 |
Correct |
5 ms |
10844 KB |
Output is correct |
18 |
Correct |
6 ms |
10840 KB |
Output is correct |
19 |
Correct |
38 ms |
10840 KB |
Output is correct |
20 |
Correct |
41 ms |
10840 KB |
Output is correct |
21 |
Correct |
35 ms |
10924 KB |
Output is correct |
22 |
Correct |
5 ms |
10844 KB |
Output is correct |
23 |
Correct |
5 ms |
10844 KB |
Output is correct |
24 |
Correct |
54 ms |
11124 KB |
Output is correct |
25 |
Correct |
54 ms |
11352 KB |
Output is correct |
26 |
Correct |
68 ms |
11244 KB |
Output is correct |
27 |
Correct |
22 ms |
10840 KB |
Output is correct |
28 |
Correct |
42 ms |
11352 KB |
Output is correct |
29 |
Correct |
56 ms |
11096 KB |
Output is correct |
30 |
Correct |
36 ms |
11096 KB |
Output is correct |
31 |
Correct |
36 ms |
11100 KB |
Output is correct |
32 |
Correct |
5 ms |
10840 KB |
Output is correct |
33 |
Correct |
187 ms |
21512 KB |
Output is correct |
34 |
Correct |
189 ms |
21584 KB |
Output is correct |
35 |
Correct |
200 ms |
21476 KB |
Output is correct |
36 |
Correct |
195 ms |
21560 KB |
Output is correct |
37 |
Correct |
196 ms |
21588 KB |
Output is correct |
38 |
Correct |
170 ms |
21412 KB |
Output is correct |
39 |
Execution timed out |
2037 ms |
33316 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10732 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
5 ms |
10852 KB |
Output is correct |
6 |
Correct |
6 ms |
10844 KB |
Output is correct |
7 |
Correct |
5 ms |
10844 KB |
Output is correct |
8 |
Correct |
5 ms |
10852 KB |
Output is correct |
9 |
Correct |
5 ms |
10844 KB |
Output is correct |
10 |
Correct |
6 ms |
10844 KB |
Output is correct |
11 |
Correct |
7 ms |
10984 KB |
Output is correct |
12 |
Correct |
86 ms |
11256 KB |
Output is correct |
13 |
Correct |
77 ms |
11240 KB |
Output is correct |
14 |
Correct |
42 ms |
11140 KB |
Output is correct |
15 |
Correct |
43 ms |
11096 KB |
Output is correct |
16 |
Correct |
5 ms |
10840 KB |
Output is correct |
17 |
Correct |
5 ms |
10844 KB |
Output is correct |
18 |
Correct |
6 ms |
10840 KB |
Output is correct |
19 |
Correct |
38 ms |
10840 KB |
Output is correct |
20 |
Correct |
41 ms |
10840 KB |
Output is correct |
21 |
Correct |
35 ms |
10924 KB |
Output is correct |
22 |
Correct |
5 ms |
10844 KB |
Output is correct |
23 |
Correct |
5 ms |
10844 KB |
Output is correct |
24 |
Correct |
54 ms |
11124 KB |
Output is correct |
25 |
Correct |
54 ms |
11352 KB |
Output is correct |
26 |
Correct |
68 ms |
11244 KB |
Output is correct |
27 |
Correct |
22 ms |
10840 KB |
Output is correct |
28 |
Correct |
42 ms |
11352 KB |
Output is correct |
29 |
Correct |
56 ms |
11096 KB |
Output is correct |
30 |
Correct |
36 ms |
11096 KB |
Output is correct |
31 |
Correct |
36 ms |
11100 KB |
Output is correct |
32 |
Correct |
5 ms |
10840 KB |
Output is correct |
33 |
Correct |
187 ms |
21512 KB |
Output is correct |
34 |
Correct |
189 ms |
21584 KB |
Output is correct |
35 |
Correct |
200 ms |
21476 KB |
Output is correct |
36 |
Correct |
195 ms |
21560 KB |
Output is correct |
37 |
Correct |
196 ms |
21588 KB |
Output is correct |
38 |
Correct |
170 ms |
21412 KB |
Output is correct |
39 |
Execution timed out |
2037 ms |
33316 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |