#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 |
12636 KB |
Output is correct |
2 |
Correct |
4 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
6 ms |
12892 KB |
Output is correct |
6 |
Correct |
6 ms |
12892 KB |
Output is correct |
7 |
Correct |
5 ms |
12892 KB |
Output is correct |
8 |
Correct |
5 ms |
12892 KB |
Output is correct |
9 |
Correct |
5 ms |
12788 KB |
Output is correct |
10 |
Correct |
5 ms |
12884 KB |
Output is correct |
11 |
Correct |
5 ms |
12892 KB |
Output is correct |
12 |
Correct |
97 ms |
13404 KB |
Output is correct |
13 |
Correct |
94 ms |
13404 KB |
Output is correct |
14 |
Correct |
49 ms |
13148 KB |
Output is correct |
15 |
Correct |
50 ms |
13148 KB |
Output is correct |
16 |
Correct |
5 ms |
12892 KB |
Output is correct |
17 |
Correct |
6 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
48 ms |
13148 KB |
Output is correct |
20 |
Correct |
43 ms |
13148 KB |
Output is correct |
21 |
Correct |
38 ms |
13148 KB |
Output is correct |
22 |
Correct |
4 ms |
12892 KB |
Output is correct |
23 |
Correct |
4 ms |
12892 KB |
Output is correct |
24 |
Correct |
61 ms |
13148 KB |
Output is correct |
25 |
Correct |
60 ms |
13348 KB |
Output is correct |
26 |
Correct |
72 ms |
13404 KB |
Output is correct |
27 |
Correct |
24 ms |
13148 KB |
Output is correct |
28 |
Correct |
45 ms |
13148 KB |
Output is correct |
29 |
Correct |
68 ms |
13148 KB |
Output is correct |
30 |
Correct |
38 ms |
13148 KB |
Output is correct |
31 |
Correct |
38 ms |
13504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12636 KB |
Output is correct |
2 |
Correct |
4 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
6 ms |
12892 KB |
Output is correct |
6 |
Correct |
6 ms |
12892 KB |
Output is correct |
7 |
Correct |
5 ms |
12892 KB |
Output is correct |
8 |
Correct |
5 ms |
12892 KB |
Output is correct |
9 |
Correct |
5 ms |
12788 KB |
Output is correct |
10 |
Correct |
5 ms |
12884 KB |
Output is correct |
11 |
Correct |
5 ms |
12892 KB |
Output is correct |
12 |
Correct |
97 ms |
13404 KB |
Output is correct |
13 |
Correct |
94 ms |
13404 KB |
Output is correct |
14 |
Correct |
49 ms |
13148 KB |
Output is correct |
15 |
Correct |
50 ms |
13148 KB |
Output is correct |
16 |
Correct |
5 ms |
12892 KB |
Output is correct |
17 |
Correct |
6 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
48 ms |
13148 KB |
Output is correct |
20 |
Correct |
43 ms |
13148 KB |
Output is correct |
21 |
Correct |
38 ms |
13148 KB |
Output is correct |
22 |
Correct |
4 ms |
12892 KB |
Output is correct |
23 |
Correct |
4 ms |
12892 KB |
Output is correct |
24 |
Correct |
61 ms |
13148 KB |
Output is correct |
25 |
Correct |
60 ms |
13348 KB |
Output is correct |
26 |
Correct |
72 ms |
13404 KB |
Output is correct |
27 |
Correct |
24 ms |
13148 KB |
Output is correct |
28 |
Correct |
45 ms |
13148 KB |
Output is correct |
29 |
Correct |
68 ms |
13148 KB |
Output is correct |
30 |
Correct |
38 ms |
13148 KB |
Output is correct |
31 |
Correct |
38 ms |
13504 KB |
Output is correct |
32 |
Correct |
5 ms |
12892 KB |
Output is correct |
33 |
Correct |
133 ms |
21588 KB |
Output is correct |
34 |
Correct |
138 ms |
21704 KB |
Output is correct |
35 |
Correct |
147 ms |
21588 KB |
Output is correct |
36 |
Correct |
132 ms |
21568 KB |
Output is correct |
37 |
Correct |
179 ms |
21752 KB |
Output is correct |
38 |
Correct |
147 ms |
21588 KB |
Output is correct |
39 |
Execution timed out |
2025 ms |
39764 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12636 KB |
Output is correct |
2 |
Correct |
4 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
6 ms |
12892 KB |
Output is correct |
6 |
Correct |
6 ms |
12892 KB |
Output is correct |
7 |
Correct |
5 ms |
12892 KB |
Output is correct |
8 |
Correct |
5 ms |
12892 KB |
Output is correct |
9 |
Correct |
5 ms |
12788 KB |
Output is correct |
10 |
Correct |
5 ms |
12884 KB |
Output is correct |
11 |
Correct |
5 ms |
12892 KB |
Output is correct |
12 |
Correct |
97 ms |
13404 KB |
Output is correct |
13 |
Correct |
94 ms |
13404 KB |
Output is correct |
14 |
Correct |
49 ms |
13148 KB |
Output is correct |
15 |
Correct |
50 ms |
13148 KB |
Output is correct |
16 |
Correct |
5 ms |
12892 KB |
Output is correct |
17 |
Correct |
6 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
48 ms |
13148 KB |
Output is correct |
20 |
Correct |
43 ms |
13148 KB |
Output is correct |
21 |
Correct |
38 ms |
13148 KB |
Output is correct |
22 |
Correct |
4 ms |
12892 KB |
Output is correct |
23 |
Correct |
4 ms |
12892 KB |
Output is correct |
24 |
Correct |
61 ms |
13148 KB |
Output is correct |
25 |
Correct |
60 ms |
13348 KB |
Output is correct |
26 |
Correct |
72 ms |
13404 KB |
Output is correct |
27 |
Correct |
24 ms |
13148 KB |
Output is correct |
28 |
Correct |
45 ms |
13148 KB |
Output is correct |
29 |
Correct |
68 ms |
13148 KB |
Output is correct |
30 |
Correct |
38 ms |
13148 KB |
Output is correct |
31 |
Correct |
38 ms |
13504 KB |
Output is correct |
32 |
Correct |
5 ms |
12892 KB |
Output is correct |
33 |
Correct |
133 ms |
21588 KB |
Output is correct |
34 |
Correct |
138 ms |
21704 KB |
Output is correct |
35 |
Correct |
147 ms |
21588 KB |
Output is correct |
36 |
Correct |
132 ms |
21568 KB |
Output is correct |
37 |
Correct |
179 ms |
21752 KB |
Output is correct |
38 |
Correct |
147 ms |
21588 KB |
Output is correct |
39 |
Execution timed out |
2025 ms |
39764 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |