#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pb push_back
#define int long long
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
const int N = 2e5 + 7;
int n;
int par[N], h[N], c[N];
vector<int> g[N];
long long dp[N], sum[N];
long long get(int node, int lim) {
long long sol = c[node];
for (int v : g[node]) sol += get(v, lim);
if (h[node] >= lim) sol = min(sol, dp[node]);
return sol;
}
void dfs(int u) {
sum[u] = c[u];
dp[u] = 0;
for (int v : g[u]) {
dfs(v);
sum[u] += sum[v];
dp[u] += get(v, h[u]);
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> par[i] >> h[i] >> c[i];
for (int i = 2; i <= n; ++i) g[par[i]].push_back(i);
dfs(1);
cout << get(1, 0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12732 KB |
Output is correct |
4 |
Correct |
3 ms |
12744 KB |
Output is correct |
5 |
Correct |
5 ms |
12892 KB |
Output is correct |
6 |
Correct |
5 ms |
12892 KB |
Output is correct |
7 |
Correct |
4 ms |
12892 KB |
Output is correct |
8 |
Correct |
4 ms |
13032 KB |
Output is correct |
9 |
Correct |
4 ms |
12888 KB |
Output is correct |
10 |
Correct |
4 ms |
12888 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
97 ms |
13472 KB |
Output is correct |
13 |
Correct |
96 ms |
13460 KB |
Output is correct |
14 |
Correct |
48 ms |
13148 KB |
Output is correct |
15 |
Correct |
48 ms |
13252 KB |
Output is correct |
16 |
Correct |
4 ms |
12784 KB |
Output is correct |
17 |
Correct |
4 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
42 ms |
13144 KB |
Output is correct |
20 |
Correct |
42 ms |
13148 KB |
Output is correct |
21 |
Correct |
38 ms |
13148 KB |
Output is correct |
22 |
Correct |
3 ms |
12888 KB |
Output is correct |
23 |
Correct |
3 ms |
12892 KB |
Output is correct |
24 |
Correct |
61 ms |
13148 KB |
Output is correct |
25 |
Correct |
59 ms |
13144 KB |
Output is correct |
26 |
Correct |
71 ms |
13464 KB |
Output is correct |
27 |
Correct |
24 ms |
13148 KB |
Output is correct |
28 |
Correct |
53 ms |
13148 KB |
Output is correct |
29 |
Correct |
64 ms |
13332 KB |
Output is correct |
30 |
Correct |
38 ms |
13144 KB |
Output is correct |
31 |
Correct |
37 ms |
13148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12732 KB |
Output is correct |
4 |
Correct |
3 ms |
12744 KB |
Output is correct |
5 |
Correct |
5 ms |
12892 KB |
Output is correct |
6 |
Correct |
5 ms |
12892 KB |
Output is correct |
7 |
Correct |
4 ms |
12892 KB |
Output is correct |
8 |
Correct |
4 ms |
13032 KB |
Output is correct |
9 |
Correct |
4 ms |
12888 KB |
Output is correct |
10 |
Correct |
4 ms |
12888 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
97 ms |
13472 KB |
Output is correct |
13 |
Correct |
96 ms |
13460 KB |
Output is correct |
14 |
Correct |
48 ms |
13148 KB |
Output is correct |
15 |
Correct |
48 ms |
13252 KB |
Output is correct |
16 |
Correct |
4 ms |
12784 KB |
Output is correct |
17 |
Correct |
4 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
42 ms |
13144 KB |
Output is correct |
20 |
Correct |
42 ms |
13148 KB |
Output is correct |
21 |
Correct |
38 ms |
13148 KB |
Output is correct |
22 |
Correct |
3 ms |
12888 KB |
Output is correct |
23 |
Correct |
3 ms |
12892 KB |
Output is correct |
24 |
Correct |
61 ms |
13148 KB |
Output is correct |
25 |
Correct |
59 ms |
13144 KB |
Output is correct |
26 |
Correct |
71 ms |
13464 KB |
Output is correct |
27 |
Correct |
24 ms |
13148 KB |
Output is correct |
28 |
Correct |
53 ms |
13148 KB |
Output is correct |
29 |
Correct |
64 ms |
13332 KB |
Output is correct |
30 |
Correct |
38 ms |
13144 KB |
Output is correct |
31 |
Correct |
37 ms |
13148 KB |
Output is correct |
32 |
Correct |
4 ms |
12892 KB |
Output is correct |
33 |
Correct |
134 ms |
21588 KB |
Output is correct |
34 |
Correct |
173 ms |
21736 KB |
Output is correct |
35 |
Correct |
153 ms |
21584 KB |
Output is correct |
36 |
Correct |
138 ms |
21732 KB |
Output is correct |
37 |
Correct |
136 ms |
21584 KB |
Output is correct |
38 |
Correct |
129 ms |
21328 KB |
Output is correct |
39 |
Execution timed out |
2007 ms |
39756 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12732 KB |
Output is correct |
4 |
Correct |
3 ms |
12744 KB |
Output is correct |
5 |
Correct |
5 ms |
12892 KB |
Output is correct |
6 |
Correct |
5 ms |
12892 KB |
Output is correct |
7 |
Correct |
4 ms |
12892 KB |
Output is correct |
8 |
Correct |
4 ms |
13032 KB |
Output is correct |
9 |
Correct |
4 ms |
12888 KB |
Output is correct |
10 |
Correct |
4 ms |
12888 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
97 ms |
13472 KB |
Output is correct |
13 |
Correct |
96 ms |
13460 KB |
Output is correct |
14 |
Correct |
48 ms |
13148 KB |
Output is correct |
15 |
Correct |
48 ms |
13252 KB |
Output is correct |
16 |
Correct |
4 ms |
12784 KB |
Output is correct |
17 |
Correct |
4 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
42 ms |
13144 KB |
Output is correct |
20 |
Correct |
42 ms |
13148 KB |
Output is correct |
21 |
Correct |
38 ms |
13148 KB |
Output is correct |
22 |
Correct |
3 ms |
12888 KB |
Output is correct |
23 |
Correct |
3 ms |
12892 KB |
Output is correct |
24 |
Correct |
61 ms |
13148 KB |
Output is correct |
25 |
Correct |
59 ms |
13144 KB |
Output is correct |
26 |
Correct |
71 ms |
13464 KB |
Output is correct |
27 |
Correct |
24 ms |
13148 KB |
Output is correct |
28 |
Correct |
53 ms |
13148 KB |
Output is correct |
29 |
Correct |
64 ms |
13332 KB |
Output is correct |
30 |
Correct |
38 ms |
13144 KB |
Output is correct |
31 |
Correct |
37 ms |
13148 KB |
Output is correct |
32 |
Correct |
4 ms |
12892 KB |
Output is correct |
33 |
Correct |
134 ms |
21588 KB |
Output is correct |
34 |
Correct |
173 ms |
21736 KB |
Output is correct |
35 |
Correct |
153 ms |
21584 KB |
Output is correct |
36 |
Correct |
138 ms |
21732 KB |
Output is correct |
37 |
Correct |
136 ms |
21584 KB |
Output is correct |
38 |
Correct |
129 ms |
21328 KB |
Output is correct |
39 |
Execution timed out |
2007 ms |
39756 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |