#include <bits/stdc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) qqbx(#a, a)
#define pary(a...) danb(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
int cnt = sizeof...(T);
((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
std::cerr << "\033[1;32m[ " << s << " ] = [ ";
for (auto it = L; it != R; ++it)
std::cerr << *it << ' ';
std::cerr << "]\033[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
using namespace std;
using ll = int64_t;
const int maxn = 200025, maxm = 10000;
int H[maxn], C[maxn];
vector<int> g[maxn];
map<int,ll,greater<>> sub[maxn];
void join(int a, int b) {
if (sub[a].size() > sub[b].size())
swap(sub[a], sub[b]);
for (auto [h, val]: sub[a])
sub[b][h] += val;
}
void dfs(int i) {
for (int j: g[i]) {
dfs(j);
join(j, i);
}
sub[i][H[i]] += C[i];
auto it = sub[i].upper_bound(H[i]);
ll v = C[i];
while (it != sub[i].end()) {
if (it->second < v) {
v -= it->second;
sub[i].erase(it++);
} else {
it->second -= v;
break;
}
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
ll tot = 0;
for (int i = 0; i < n; i++) {
int A;
cin >> A >> H[i] >> C[i];
tot += C[i];
--A;
if (i) g[A].push_back(i);
}
dfs(0);
ll best = 0;
for (auto [h, val]: sub[0]) {
best += val;
}
cout << tot - best << '\n';
}
Compilation message
worst_reporter2.cpp: In function 'void join(int, int)':
worst_reporter2.cpp:34:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
34 | for (auto [h, val]: sub[a])
| ^
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:69:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
69 | for (auto [h, val]: sub[0]) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
14412 KB |
Output is correct |
2 |
Correct |
11 ms |
14408 KB |
Output is correct |
3 |
Correct |
11 ms |
14284 KB |
Output is correct |
4 |
Correct |
11 ms |
14412 KB |
Output is correct |
5 |
Correct |
18 ms |
15436 KB |
Output is correct |
6 |
Correct |
16 ms |
15052 KB |
Output is correct |
7 |
Correct |
15 ms |
14852 KB |
Output is correct |
8 |
Correct |
16 ms |
15436 KB |
Output is correct |
9 |
Correct |
18 ms |
15104 KB |
Output is correct |
10 |
Correct |
15 ms |
14796 KB |
Output is correct |
11 |
Correct |
13 ms |
14668 KB |
Output is correct |
12 |
Correct |
17 ms |
14924 KB |
Output is correct |
13 |
Correct |
12 ms |
14924 KB |
Output is correct |
14 |
Correct |
16 ms |
14812 KB |
Output is correct |
15 |
Correct |
15 ms |
14796 KB |
Output is correct |
16 |
Correct |
18 ms |
15820 KB |
Output is correct |
17 |
Correct |
16 ms |
15180 KB |
Output is correct |
18 |
Correct |
14 ms |
14668 KB |
Output is correct |
19 |
Correct |
19 ms |
15056 KB |
Output is correct |
20 |
Correct |
14 ms |
14836 KB |
Output is correct |
21 |
Correct |
13 ms |
14796 KB |
Output is correct |
22 |
Correct |
14 ms |
15052 KB |
Output is correct |
23 |
Correct |
14 ms |
14720 KB |
Output is correct |
24 |
Correct |
14 ms |
15076 KB |
Output is correct |
25 |
Correct |
17 ms |
14796 KB |
Output is correct |
26 |
Correct |
18 ms |
15308 KB |
Output is correct |
27 |
Correct |
16 ms |
15052 KB |
Output is correct |
28 |
Correct |
16 ms |
15048 KB |
Output is correct |
29 |
Correct |
18 ms |
15296 KB |
Output is correct |
30 |
Correct |
15 ms |
15248 KB |
Output is correct |
31 |
Correct |
18 ms |
15180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
14412 KB |
Output is correct |
2 |
Correct |
11 ms |
14408 KB |
Output is correct |
3 |
Correct |
11 ms |
14284 KB |
Output is correct |
4 |
Correct |
11 ms |
14412 KB |
Output is correct |
5 |
Correct |
18 ms |
15436 KB |
Output is correct |
6 |
Correct |
16 ms |
15052 KB |
Output is correct |
7 |
Correct |
15 ms |
14852 KB |
Output is correct |
8 |
Correct |
16 ms |
15436 KB |
Output is correct |
9 |
Correct |
18 ms |
15104 KB |
Output is correct |
10 |
Correct |
15 ms |
14796 KB |
Output is correct |
11 |
Correct |
13 ms |
14668 KB |
Output is correct |
12 |
Correct |
17 ms |
14924 KB |
Output is correct |
13 |
Correct |
12 ms |
14924 KB |
Output is correct |
14 |
Correct |
16 ms |
14812 KB |
Output is correct |
15 |
Correct |
15 ms |
14796 KB |
Output is correct |
16 |
Correct |
18 ms |
15820 KB |
Output is correct |
17 |
Correct |
16 ms |
15180 KB |
Output is correct |
18 |
Correct |
14 ms |
14668 KB |
Output is correct |
19 |
Correct |
19 ms |
15056 KB |
Output is correct |
20 |
Correct |
14 ms |
14836 KB |
Output is correct |
21 |
Correct |
13 ms |
14796 KB |
Output is correct |
22 |
Correct |
14 ms |
15052 KB |
Output is correct |
23 |
Correct |
14 ms |
14720 KB |
Output is correct |
24 |
Correct |
14 ms |
15076 KB |
Output is correct |
25 |
Correct |
17 ms |
14796 KB |
Output is correct |
26 |
Correct |
18 ms |
15308 KB |
Output is correct |
27 |
Correct |
16 ms |
15052 KB |
Output is correct |
28 |
Correct |
16 ms |
15048 KB |
Output is correct |
29 |
Correct |
18 ms |
15296 KB |
Output is correct |
30 |
Correct |
15 ms |
15248 KB |
Output is correct |
31 |
Correct |
18 ms |
15180 KB |
Output is correct |
32 |
Correct |
16 ms |
15436 KB |
Output is correct |
33 |
Correct |
418 ms |
73520 KB |
Output is correct |
34 |
Correct |
329 ms |
51364 KB |
Output is correct |
35 |
Correct |
484 ms |
73248 KB |
Output is correct |
36 |
Correct |
344 ms |
51500 KB |
Output is correct |
37 |
Correct |
252 ms |
32396 KB |
Output is correct |
38 |
Correct |
236 ms |
28072 KB |
Output is correct |
39 |
Correct |
181 ms |
40516 KB |
Output is correct |
40 |
Correct |
151 ms |
40568 KB |
Output is correct |
41 |
Correct |
120 ms |
40444 KB |
Output is correct |
42 |
Correct |
163 ms |
32836 KB |
Output is correct |
43 |
Correct |
155 ms |
32676 KB |
Output is correct |
44 |
Correct |
381 ms |
101324 KB |
Output is correct |
45 |
Correct |
308 ms |
65588 KB |
Output is correct |
46 |
Correct |
112 ms |
27936 KB |
Output is correct |
47 |
Correct |
312 ms |
42844 KB |
Output is correct |
48 |
Correct |
145 ms |
35920 KB |
Output is correct |
49 |
Correct |
117 ms |
35776 KB |
Output is correct |
50 |
Correct |
356 ms |
44620 KB |
Output is correct |
51 |
Correct |
119 ms |
31936 KB |
Output is correct |
52 |
Correct |
327 ms |
43316 KB |
Output is correct |
53 |
Correct |
138 ms |
36236 KB |
Output is correct |
54 |
Correct |
236 ms |
53072 KB |
Output is correct |
55 |
Correct |
240 ms |
45256 KB |
Output is correct |
56 |
Correct |
196 ms |
48160 KB |
Output is correct |
57 |
Correct |
189 ms |
49776 KB |
Output is correct |
58 |
Correct |
199 ms |
51472 KB |
Output is correct |
59 |
Correct |
199 ms |
51396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
14412 KB |
Output is correct |
2 |
Correct |
11 ms |
14408 KB |
Output is correct |
3 |
Correct |
11 ms |
14284 KB |
Output is correct |
4 |
Correct |
11 ms |
14412 KB |
Output is correct |
5 |
Correct |
18 ms |
15436 KB |
Output is correct |
6 |
Correct |
16 ms |
15052 KB |
Output is correct |
7 |
Correct |
15 ms |
14852 KB |
Output is correct |
8 |
Correct |
16 ms |
15436 KB |
Output is correct |
9 |
Correct |
18 ms |
15104 KB |
Output is correct |
10 |
Correct |
15 ms |
14796 KB |
Output is correct |
11 |
Correct |
13 ms |
14668 KB |
Output is correct |
12 |
Correct |
17 ms |
14924 KB |
Output is correct |
13 |
Correct |
12 ms |
14924 KB |
Output is correct |
14 |
Correct |
16 ms |
14812 KB |
Output is correct |
15 |
Correct |
15 ms |
14796 KB |
Output is correct |
16 |
Correct |
18 ms |
15820 KB |
Output is correct |
17 |
Correct |
16 ms |
15180 KB |
Output is correct |
18 |
Correct |
14 ms |
14668 KB |
Output is correct |
19 |
Correct |
19 ms |
15056 KB |
Output is correct |
20 |
Correct |
14 ms |
14836 KB |
Output is correct |
21 |
Correct |
13 ms |
14796 KB |
Output is correct |
22 |
Correct |
14 ms |
15052 KB |
Output is correct |
23 |
Correct |
14 ms |
14720 KB |
Output is correct |
24 |
Correct |
14 ms |
15076 KB |
Output is correct |
25 |
Correct |
17 ms |
14796 KB |
Output is correct |
26 |
Correct |
18 ms |
15308 KB |
Output is correct |
27 |
Correct |
16 ms |
15052 KB |
Output is correct |
28 |
Correct |
16 ms |
15048 KB |
Output is correct |
29 |
Correct |
18 ms |
15296 KB |
Output is correct |
30 |
Correct |
15 ms |
15248 KB |
Output is correct |
31 |
Correct |
18 ms |
15180 KB |
Output is correct |
32 |
Correct |
16 ms |
15436 KB |
Output is correct |
33 |
Correct |
418 ms |
73520 KB |
Output is correct |
34 |
Correct |
329 ms |
51364 KB |
Output is correct |
35 |
Correct |
484 ms |
73248 KB |
Output is correct |
36 |
Correct |
344 ms |
51500 KB |
Output is correct |
37 |
Correct |
252 ms |
32396 KB |
Output is correct |
38 |
Correct |
236 ms |
28072 KB |
Output is correct |
39 |
Correct |
181 ms |
40516 KB |
Output is correct |
40 |
Correct |
151 ms |
40568 KB |
Output is correct |
41 |
Correct |
120 ms |
40444 KB |
Output is correct |
42 |
Correct |
163 ms |
32836 KB |
Output is correct |
43 |
Correct |
155 ms |
32676 KB |
Output is correct |
44 |
Correct |
381 ms |
101324 KB |
Output is correct |
45 |
Correct |
308 ms |
65588 KB |
Output is correct |
46 |
Correct |
112 ms |
27936 KB |
Output is correct |
47 |
Correct |
312 ms |
42844 KB |
Output is correct |
48 |
Correct |
145 ms |
35920 KB |
Output is correct |
49 |
Correct |
117 ms |
35776 KB |
Output is correct |
50 |
Correct |
356 ms |
44620 KB |
Output is correct |
51 |
Correct |
119 ms |
31936 KB |
Output is correct |
52 |
Correct |
327 ms |
43316 KB |
Output is correct |
53 |
Correct |
138 ms |
36236 KB |
Output is correct |
54 |
Correct |
236 ms |
53072 KB |
Output is correct |
55 |
Correct |
240 ms |
45256 KB |
Output is correct |
56 |
Correct |
196 ms |
48160 KB |
Output is correct |
57 |
Correct |
189 ms |
49776 KB |
Output is correct |
58 |
Correct |
199 ms |
51472 KB |
Output is correct |
59 |
Correct |
199 ms |
51396 KB |
Output is correct |
60 |
Correct |
13 ms |
14412 KB |
Output is correct |
61 |
Incorrect |
10 ms |
14368 KB |
Output isn't correct |
62 |
Halted |
0 ms |
0 KB |
- |