#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e5 + 5;
int n;
int a[N], c[N], dp[N];
vector<int> g[N];
map<int, long long> mp[N];
void dfs(int u) {
for (int v : g[u]) {
dfs(v);
if (mp[u].size() < mp[v].size()) {
mp[u].swap(mp[v]);
}
for (auto [x, y] : mp[v]) {
mp[u][x] += y;
}
}
mp[u][a[u]] += c[u];
for (auto it = mp[u].upper_bound(a[u]); it != mp[u].end(); it = mp[u].erase(it)) {
auto &delta = (*it).second;
if (c[u] < delta) {
delta -= c[u];
break;
}
c[u] -= delta;
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
long long res = 0;
for (int i = 1; i <= n; ++i) {
int p; cin >> p >> a[i] >> c[i];
a[i] = 1e9 - a[i] + 1;
res += c[i];
if (p ^ i) {
g[p].push_back(i);
}
}
dfs(1);
for (auto [x, y] : mp[1]) {
res -= y;
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14428 KB |
Output is correct |
2 |
Correct |
4 ms |
14428 KB |
Output is correct |
3 |
Correct |
4 ms |
14428 KB |
Output is correct |
4 |
Correct |
4 ms |
14428 KB |
Output is correct |
5 |
Correct |
7 ms |
15708 KB |
Output is correct |
6 |
Correct |
7 ms |
15196 KB |
Output is correct |
7 |
Correct |
6 ms |
15120 KB |
Output is correct |
8 |
Correct |
8 ms |
15592 KB |
Output is correct |
9 |
Correct |
6 ms |
15196 KB |
Output is correct |
10 |
Correct |
6 ms |
14940 KB |
Output is correct |
11 |
Correct |
5 ms |
14940 KB |
Output is correct |
12 |
Correct |
7 ms |
15448 KB |
Output is correct |
13 |
Correct |
6 ms |
15452 KB |
Output is correct |
14 |
Correct |
7 ms |
15196 KB |
Output is correct |
15 |
Correct |
6 ms |
15196 KB |
Output is correct |
16 |
Correct |
9 ms |
15976 KB |
Output is correct |
17 |
Correct |
7 ms |
15488 KB |
Output is correct |
18 |
Correct |
6 ms |
14936 KB |
Output is correct |
19 |
Correct |
7 ms |
15448 KB |
Output is correct |
20 |
Correct |
6 ms |
15196 KB |
Output is correct |
21 |
Correct |
6 ms |
15196 KB |
Output is correct |
22 |
Correct |
7 ms |
15196 KB |
Output is correct |
23 |
Correct |
6 ms |
14940 KB |
Output is correct |
24 |
Correct |
6 ms |
15504 KB |
Output is correct |
25 |
Correct |
6 ms |
15088 KB |
Output is correct |
26 |
Correct |
6 ms |
15452 KB |
Output is correct |
27 |
Correct |
7 ms |
15452 KB |
Output is correct |
28 |
Correct |
7 ms |
15472 KB |
Output is correct |
29 |
Correct |
6 ms |
15708 KB |
Output is correct |
30 |
Correct |
7 ms |
15680 KB |
Output is correct |
31 |
Correct |
6 ms |
15452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14428 KB |
Output is correct |
2 |
Correct |
4 ms |
14428 KB |
Output is correct |
3 |
Correct |
4 ms |
14428 KB |
Output is correct |
4 |
Correct |
4 ms |
14428 KB |
Output is correct |
5 |
Correct |
7 ms |
15708 KB |
Output is correct |
6 |
Correct |
7 ms |
15196 KB |
Output is correct |
7 |
Correct |
6 ms |
15120 KB |
Output is correct |
8 |
Correct |
8 ms |
15592 KB |
Output is correct |
9 |
Correct |
6 ms |
15196 KB |
Output is correct |
10 |
Correct |
6 ms |
14940 KB |
Output is correct |
11 |
Correct |
5 ms |
14940 KB |
Output is correct |
12 |
Correct |
7 ms |
15448 KB |
Output is correct |
13 |
Correct |
6 ms |
15452 KB |
Output is correct |
14 |
Correct |
7 ms |
15196 KB |
Output is correct |
15 |
Correct |
6 ms |
15196 KB |
Output is correct |
16 |
Correct |
9 ms |
15976 KB |
Output is correct |
17 |
Correct |
7 ms |
15488 KB |
Output is correct |
18 |
Correct |
6 ms |
14936 KB |
Output is correct |
19 |
Correct |
7 ms |
15448 KB |
Output is correct |
20 |
Correct |
6 ms |
15196 KB |
Output is correct |
21 |
Correct |
6 ms |
15196 KB |
Output is correct |
22 |
Correct |
7 ms |
15196 KB |
Output is correct |
23 |
Correct |
6 ms |
14940 KB |
Output is correct |
24 |
Correct |
6 ms |
15504 KB |
Output is correct |
25 |
Correct |
6 ms |
15088 KB |
Output is correct |
26 |
Correct |
6 ms |
15452 KB |
Output is correct |
27 |
Correct |
7 ms |
15452 KB |
Output is correct |
28 |
Correct |
7 ms |
15472 KB |
Output is correct |
29 |
Correct |
6 ms |
15708 KB |
Output is correct |
30 |
Correct |
7 ms |
15680 KB |
Output is correct |
31 |
Correct |
6 ms |
15452 KB |
Output is correct |
32 |
Correct |
9 ms |
15708 KB |
Output is correct |
33 |
Correct |
203 ms |
78748 KB |
Output is correct |
34 |
Correct |
144 ms |
53844 KB |
Output is correct |
35 |
Correct |
195 ms |
75600 KB |
Output is correct |
36 |
Correct |
144 ms |
53844 KB |
Output is correct |
37 |
Correct |
99 ms |
34900 KB |
Output is correct |
38 |
Correct |
77 ms |
30432 KB |
Output is correct |
39 |
Correct |
90 ms |
55632 KB |
Output is correct |
40 |
Correct |
81 ms |
55492 KB |
Output is correct |
41 |
Correct |
71 ms |
55636 KB |
Output is correct |
42 |
Correct |
79 ms |
41628 KB |
Output is correct |
43 |
Correct |
74 ms |
41556 KB |
Output is correct |
44 |
Correct |
206 ms |
103636 KB |
Output is correct |
45 |
Correct |
151 ms |
68064 KB |
Output is correct |
46 |
Correct |
49 ms |
30536 KB |
Output is correct |
47 |
Correct |
128 ms |
51536 KB |
Output is correct |
48 |
Correct |
69 ms |
44880 KB |
Output is correct |
49 |
Correct |
58 ms |
44436 KB |
Output is correct |
50 |
Correct |
123 ms |
46032 KB |
Output is correct |
51 |
Correct |
54 ms |
33488 KB |
Output is correct |
52 |
Correct |
136 ms |
52104 KB |
Output is correct |
53 |
Correct |
68 ms |
45004 KB |
Output is correct |
54 |
Correct |
66 ms |
56056 KB |
Output is correct |
55 |
Correct |
103 ms |
53076 KB |
Output is correct |
56 |
Correct |
101 ms |
58816 KB |
Output is correct |
57 |
Correct |
95 ms |
62036 KB |
Output is correct |
58 |
Correct |
102 ms |
59668 KB |
Output is correct |
59 |
Correct |
97 ms |
59472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14428 KB |
Output is correct |
2 |
Correct |
4 ms |
14428 KB |
Output is correct |
3 |
Correct |
4 ms |
14428 KB |
Output is correct |
4 |
Correct |
4 ms |
14428 KB |
Output is correct |
5 |
Correct |
7 ms |
15708 KB |
Output is correct |
6 |
Correct |
7 ms |
15196 KB |
Output is correct |
7 |
Correct |
6 ms |
15120 KB |
Output is correct |
8 |
Correct |
8 ms |
15592 KB |
Output is correct |
9 |
Correct |
6 ms |
15196 KB |
Output is correct |
10 |
Correct |
6 ms |
14940 KB |
Output is correct |
11 |
Correct |
5 ms |
14940 KB |
Output is correct |
12 |
Correct |
7 ms |
15448 KB |
Output is correct |
13 |
Correct |
6 ms |
15452 KB |
Output is correct |
14 |
Correct |
7 ms |
15196 KB |
Output is correct |
15 |
Correct |
6 ms |
15196 KB |
Output is correct |
16 |
Correct |
9 ms |
15976 KB |
Output is correct |
17 |
Correct |
7 ms |
15488 KB |
Output is correct |
18 |
Correct |
6 ms |
14936 KB |
Output is correct |
19 |
Correct |
7 ms |
15448 KB |
Output is correct |
20 |
Correct |
6 ms |
15196 KB |
Output is correct |
21 |
Correct |
6 ms |
15196 KB |
Output is correct |
22 |
Correct |
7 ms |
15196 KB |
Output is correct |
23 |
Correct |
6 ms |
14940 KB |
Output is correct |
24 |
Correct |
6 ms |
15504 KB |
Output is correct |
25 |
Correct |
6 ms |
15088 KB |
Output is correct |
26 |
Correct |
6 ms |
15452 KB |
Output is correct |
27 |
Correct |
7 ms |
15452 KB |
Output is correct |
28 |
Correct |
7 ms |
15472 KB |
Output is correct |
29 |
Correct |
6 ms |
15708 KB |
Output is correct |
30 |
Correct |
7 ms |
15680 KB |
Output is correct |
31 |
Correct |
6 ms |
15452 KB |
Output is correct |
32 |
Correct |
9 ms |
15708 KB |
Output is correct |
33 |
Correct |
203 ms |
78748 KB |
Output is correct |
34 |
Correct |
144 ms |
53844 KB |
Output is correct |
35 |
Correct |
195 ms |
75600 KB |
Output is correct |
36 |
Correct |
144 ms |
53844 KB |
Output is correct |
37 |
Correct |
99 ms |
34900 KB |
Output is correct |
38 |
Correct |
77 ms |
30432 KB |
Output is correct |
39 |
Correct |
90 ms |
55632 KB |
Output is correct |
40 |
Correct |
81 ms |
55492 KB |
Output is correct |
41 |
Correct |
71 ms |
55636 KB |
Output is correct |
42 |
Correct |
79 ms |
41628 KB |
Output is correct |
43 |
Correct |
74 ms |
41556 KB |
Output is correct |
44 |
Correct |
206 ms |
103636 KB |
Output is correct |
45 |
Correct |
151 ms |
68064 KB |
Output is correct |
46 |
Correct |
49 ms |
30536 KB |
Output is correct |
47 |
Correct |
128 ms |
51536 KB |
Output is correct |
48 |
Correct |
69 ms |
44880 KB |
Output is correct |
49 |
Correct |
58 ms |
44436 KB |
Output is correct |
50 |
Correct |
123 ms |
46032 KB |
Output is correct |
51 |
Correct |
54 ms |
33488 KB |
Output is correct |
52 |
Correct |
136 ms |
52104 KB |
Output is correct |
53 |
Correct |
68 ms |
45004 KB |
Output is correct |
54 |
Correct |
66 ms |
56056 KB |
Output is correct |
55 |
Correct |
103 ms |
53076 KB |
Output is correct |
56 |
Correct |
101 ms |
58816 KB |
Output is correct |
57 |
Correct |
95 ms |
62036 KB |
Output is correct |
58 |
Correct |
102 ms |
59668 KB |
Output is correct |
59 |
Correct |
97 ms |
59472 KB |
Output is correct |
60 |
Runtime error |
249 ms |
524288 KB |
Execution killed with signal 9 |
61 |
Halted |
0 ms |
0 KB |
- |