#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
//const int mxN = 2e5+5;
const int mxN = 5e3+5;
const ll inf = 1e18;
int N, A[mxN], H[mxN], C[mxN];
vector<int> al[mxN];
ll dp[mxN][mxN];
void dfs(int u) {
FOR(x,0,u) dp[u][x] = H[x] == H[u] ? 0 : C[u];
for (int v : al[u]) {
dfs(v);
FOR(x,0,u){
dp[u][x] += min(dp[v][x], H[x] <= H[v] ? dp[v][v] : inf);
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N;
FOR(i,1,N){
cin >> A[i] >> H[i] >> C[i];
if (i != 1) al[A[i]].push_back(i);
}
H[0] = 1;
dfs(1);
cout << min(dp[1][0], dp[1][1]) << '\n';
}
# |
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 |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
89 ms |
117428 KB |
Output is correct |
6 |
Correct |
89 ms |
117492 KB |
Output is correct |
7 |
Correct |
96 ms |
117524 KB |
Output is correct |
8 |
Correct |
90 ms |
117520 KB |
Output is correct |
9 |
Correct |
89 ms |
117560 KB |
Output is correct |
10 |
Correct |
97 ms |
117552 KB |
Output is correct |
11 |
Correct |
78 ms |
117592 KB |
Output is correct |
12 |
Correct |
107 ms |
118144 KB |
Output is correct |
13 |
Correct |
115 ms |
118072 KB |
Output is correct |
14 |
Correct |
112 ms |
117940 KB |
Output is correct |
15 |
Correct |
109 ms |
117876 KB |
Output is correct |
16 |
Correct |
97 ms |
117556 KB |
Output is correct |
17 |
Correct |
85 ms |
117572 KB |
Output is correct |
18 |
Correct |
94 ms |
117568 KB |
Output is correct |
19 |
Correct |
88 ms |
117744 KB |
Output is correct |
20 |
Correct |
89 ms |
117828 KB |
Output is correct |
21 |
Correct |
105 ms |
117764 KB |
Output is correct |
22 |
Correct |
61 ms |
117536 KB |
Output is correct |
23 |
Correct |
63 ms |
117524 KB |
Output is correct |
24 |
Correct |
108 ms |
117908 KB |
Output is correct |
25 |
Correct |
95 ms |
117860 KB |
Output is correct |
26 |
Correct |
84 ms |
118212 KB |
Output is correct |
27 |
Correct |
73 ms |
117812 KB |
Output is correct |
28 |
Correct |
75 ms |
117924 KB |
Output is correct |
29 |
Correct |
80 ms |
117924 KB |
Output is correct |
30 |
Correct |
92 ms |
117832 KB |
Output is correct |
31 |
Correct |
85 ms |
117928 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 |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
89 ms |
117428 KB |
Output is correct |
6 |
Correct |
89 ms |
117492 KB |
Output is correct |
7 |
Correct |
96 ms |
117524 KB |
Output is correct |
8 |
Correct |
90 ms |
117520 KB |
Output is correct |
9 |
Correct |
89 ms |
117560 KB |
Output is correct |
10 |
Correct |
97 ms |
117552 KB |
Output is correct |
11 |
Correct |
78 ms |
117592 KB |
Output is correct |
12 |
Correct |
107 ms |
118144 KB |
Output is correct |
13 |
Correct |
115 ms |
118072 KB |
Output is correct |
14 |
Correct |
112 ms |
117940 KB |
Output is correct |
15 |
Correct |
109 ms |
117876 KB |
Output is correct |
16 |
Correct |
97 ms |
117556 KB |
Output is correct |
17 |
Correct |
85 ms |
117572 KB |
Output is correct |
18 |
Correct |
94 ms |
117568 KB |
Output is correct |
19 |
Correct |
88 ms |
117744 KB |
Output is correct |
20 |
Correct |
89 ms |
117828 KB |
Output is correct |
21 |
Correct |
105 ms |
117764 KB |
Output is correct |
22 |
Correct |
61 ms |
117536 KB |
Output is correct |
23 |
Correct |
63 ms |
117524 KB |
Output is correct |
24 |
Correct |
108 ms |
117908 KB |
Output is correct |
25 |
Correct |
95 ms |
117860 KB |
Output is correct |
26 |
Correct |
84 ms |
118212 KB |
Output is correct |
27 |
Correct |
73 ms |
117812 KB |
Output is correct |
28 |
Correct |
75 ms |
117924 KB |
Output is correct |
29 |
Correct |
80 ms |
117924 KB |
Output is correct |
30 |
Correct |
92 ms |
117832 KB |
Output is correct |
31 |
Correct |
85 ms |
117928 KB |
Output is correct |
32 |
Correct |
87 ms |
117556 KB |
Output is correct |
33 |
Runtime error |
87 ms |
65868 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
89 ms |
117428 KB |
Output is correct |
6 |
Correct |
89 ms |
117492 KB |
Output is correct |
7 |
Correct |
96 ms |
117524 KB |
Output is correct |
8 |
Correct |
90 ms |
117520 KB |
Output is correct |
9 |
Correct |
89 ms |
117560 KB |
Output is correct |
10 |
Correct |
97 ms |
117552 KB |
Output is correct |
11 |
Correct |
78 ms |
117592 KB |
Output is correct |
12 |
Correct |
107 ms |
118144 KB |
Output is correct |
13 |
Correct |
115 ms |
118072 KB |
Output is correct |
14 |
Correct |
112 ms |
117940 KB |
Output is correct |
15 |
Correct |
109 ms |
117876 KB |
Output is correct |
16 |
Correct |
97 ms |
117556 KB |
Output is correct |
17 |
Correct |
85 ms |
117572 KB |
Output is correct |
18 |
Correct |
94 ms |
117568 KB |
Output is correct |
19 |
Correct |
88 ms |
117744 KB |
Output is correct |
20 |
Correct |
89 ms |
117828 KB |
Output is correct |
21 |
Correct |
105 ms |
117764 KB |
Output is correct |
22 |
Correct |
61 ms |
117536 KB |
Output is correct |
23 |
Correct |
63 ms |
117524 KB |
Output is correct |
24 |
Correct |
108 ms |
117908 KB |
Output is correct |
25 |
Correct |
95 ms |
117860 KB |
Output is correct |
26 |
Correct |
84 ms |
118212 KB |
Output is correct |
27 |
Correct |
73 ms |
117812 KB |
Output is correct |
28 |
Correct |
75 ms |
117924 KB |
Output is correct |
29 |
Correct |
80 ms |
117924 KB |
Output is correct |
30 |
Correct |
92 ms |
117832 KB |
Output is correct |
31 |
Correct |
85 ms |
117928 KB |
Output is correct |
32 |
Correct |
87 ms |
117556 KB |
Output is correct |
33 |
Runtime error |
87 ms |
65868 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |