# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
414770 | 2021-05-31T07:34:24 Z | 장태환(#7553) | Worst Reporter 4 (JOI21_worst_reporter4) | C++17 | 427 ms | 119276 KB |
#include <iostream> #include <algorithm> #include <vector> #include <map> #define int long long using namespace std; map<int,int>stl[200100]; int uf[200100]; int f(int n) { return uf[n] == n ? n : uf[n] = f(uf[n]); } void u(int n, int m) { n = f(n); m = f(m); if (stl[n].size() > stl[m].size()) { swap(n, m); } uf[n] = m; for (auto it = stl[n].begin(); it != stl[n].end(); it++) { stl[m][(*it).first] += (*it).second; } } vector<int>nex[200100]; int H[200100]; int C[200100]; void treedp(int n) { int i; for (i = 0; i < nex[n].size(); i++) { treedp(nex[n][i]); u(n, nex[n][i]); } int po = f(n); int curc = C[n]; auto it = stl[po].lower_bound(H[n]); it--; while (1) { if ((*it).second <= curc) { curc -= (*it).second; stl[po].erase(it--); } else { it->second -= curc; break; } } stl[po][H[n]] += C[n]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; int i; int ans = 0; for (i = 0; i < N; i++) { uf[i] = i; int a, b, c; cin >> a >> b >> c; if (i) { nex[a-1].push_back(i); } H[i] = b; C[i] = c; stl[i][0] += 1LL << 30; ans += c; } treedp(0); auto it = stl[f(0)].end(); while (1) { it--; if (it == stl[f(0)].begin()) break; ans -= (*it).second; } cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 14412 KB | Output is correct |
2 | Correct | 9 ms | 14412 KB | Output is correct |
3 | Correct | 9 ms | 14412 KB | Output is correct |
4 | Correct | 9 ms | 14412 KB | Output is correct |
5 | Correct | 16 ms | 15948 KB | Output is correct |
6 | Correct | 14 ms | 15560 KB | Output is correct |
7 | Correct | 16 ms | 15336 KB | Output is correct |
8 | Correct | 16 ms | 16076 KB | Output is correct |
9 | Correct | 14 ms | 15524 KB | Output is correct |
10 | Correct | 13 ms | 15328 KB | Output is correct |
11 | Correct | 12 ms | 15204 KB | Output is correct |
12 | Correct | 13 ms | 15640 KB | Output is correct |
13 | Correct | 13 ms | 15592 KB | Output is correct |
14 | Correct | 13 ms | 15336 KB | Output is correct |
15 | Correct | 13 ms | 15416 KB | Output is correct |
16 | Correct | 16 ms | 16320 KB | Output is correct |
17 | Correct | 14 ms | 15692 KB | Output is correct |
18 | Correct | 12 ms | 15184 KB | Output is correct |
19 | Correct | 15 ms | 15692 KB | Output is correct |
20 | Correct | 13 ms | 15492 KB | Output is correct |
21 | Correct | 12 ms | 15460 KB | Output is correct |
22 | Correct | 13 ms | 15644 KB | Output is correct |
23 | Correct | 12 ms | 15308 KB | Output is correct |
24 | Correct | 13 ms | 15692 KB | Output is correct |
25 | Correct | 13 ms | 15444 KB | Output is correct |
26 | Correct | 12 ms | 15564 KB | Output is correct |
27 | Correct | 14 ms | 15584 KB | Output is correct |
28 | Correct | 13 ms | 15756 KB | Output is correct |
29 | Correct | 13 ms | 15848 KB | Output is correct |
30 | Correct | 15 ms | 15844 KB | Output is correct |
31 | Correct | 13 ms | 15812 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 15948 KB | Output is correct |
2 | Correct | 427 ms | 94732 KB | Output is correct |
3 | Correct | 342 ms | 70120 KB | Output is correct |
4 | Correct | 421 ms | 91732 KB | Output is correct |
5 | Correct | 343 ms | 69924 KB | Output is correct |
6 | Correct | 254 ms | 50984 KB | Output is correct |
7 | Correct | 234 ms | 46660 KB | Output is correct |
8 | Correct | 186 ms | 64984 KB | Output is correct |
9 | Correct | 180 ms | 64952 KB | Output is correct |
10 | Correct | 134 ms | 64952 KB | Output is correct |
11 | Correct | 176 ms | 54084 KB | Output is correct |
12 | Correct | 171 ms | 54132 KB | Output is correct |
13 | Correct | 363 ms | 119276 KB | Output is correct |
14 | Correct | 258 ms | 83880 KB | Output is correct |
15 | Correct | 129 ms | 46004 KB | Output is correct |
16 | Correct | 324 ms | 64068 KB | Output is correct |
17 | Correct | 173 ms | 57080 KB | Output is correct |
18 | Correct | 132 ms | 56936 KB | Output is correct |
19 | Correct | 300 ms | 62452 KB | Output is correct |
20 | Correct | 138 ms | 49992 KB | Output is correct |
21 | Correct | 305 ms | 65028 KB | Output is correct |
22 | Correct | 162 ms | 57864 KB | Output is correct |
23 | Correct | 150 ms | 65108 KB | Output is correct |
24 | Correct | 285 ms | 66500 KB | Output is correct |
25 | Correct | 234 ms | 70048 KB | Output is correct |
26 | Correct | 217 ms | 72260 KB | Output is correct |
27 | Correct | 239 ms | 72056 KB | Output is correct |
28 | Correct | 221 ms | 72004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 14412 KB | Output is correct |
2 | Correct | 9 ms | 14412 KB | Output is correct |
3 | Correct | 9 ms | 14412 KB | Output is correct |
4 | Correct | 9 ms | 14412 KB | Output is correct |
5 | Correct | 16 ms | 15948 KB | Output is correct |
6 | Correct | 14 ms | 15560 KB | Output is correct |
7 | Correct | 16 ms | 15336 KB | Output is correct |
8 | Correct | 16 ms | 16076 KB | Output is correct |
9 | Correct | 14 ms | 15524 KB | Output is correct |
10 | Correct | 13 ms | 15328 KB | Output is correct |
11 | Correct | 12 ms | 15204 KB | Output is correct |
12 | Correct | 13 ms | 15640 KB | Output is correct |
13 | Correct | 13 ms | 15592 KB | Output is correct |
14 | Correct | 13 ms | 15336 KB | Output is correct |
15 | Correct | 13 ms | 15416 KB | Output is correct |
16 | Correct | 16 ms | 16320 KB | Output is correct |
17 | Correct | 14 ms | 15692 KB | Output is correct |
18 | Correct | 12 ms | 15184 KB | Output is correct |
19 | Correct | 15 ms | 15692 KB | Output is correct |
20 | Correct | 13 ms | 15492 KB | Output is correct |
21 | Correct | 12 ms | 15460 KB | Output is correct |
22 | Correct | 13 ms | 15644 KB | Output is correct |
23 | Correct | 12 ms | 15308 KB | Output is correct |
24 | Correct | 13 ms | 15692 KB | Output is correct |
25 | Correct | 13 ms | 15444 KB | Output is correct |
26 | Correct | 12 ms | 15564 KB | Output is correct |
27 | Correct | 14 ms | 15584 KB | Output is correct |
28 | Correct | 13 ms | 15756 KB | Output is correct |
29 | Correct | 13 ms | 15848 KB | Output is correct |
30 | Correct | 15 ms | 15844 KB | Output is correct |
31 | Correct | 13 ms | 15812 KB | Output is correct |
32 | Correct | 15 ms | 15948 KB | Output is correct |
33 | Correct | 427 ms | 94732 KB | Output is correct |
34 | Correct | 342 ms | 70120 KB | Output is correct |
35 | Correct | 421 ms | 91732 KB | Output is correct |
36 | Correct | 343 ms | 69924 KB | Output is correct |
37 | Correct | 254 ms | 50984 KB | Output is correct |
38 | Correct | 234 ms | 46660 KB | Output is correct |
39 | Correct | 186 ms | 64984 KB | Output is correct |
40 | Correct | 180 ms | 64952 KB | Output is correct |
41 | Correct | 134 ms | 64952 KB | Output is correct |
42 | Correct | 176 ms | 54084 KB | Output is correct |
43 | Correct | 171 ms | 54132 KB | Output is correct |
44 | Correct | 363 ms | 119276 KB | Output is correct |
45 | Correct | 258 ms | 83880 KB | Output is correct |
46 | Correct | 129 ms | 46004 KB | Output is correct |
47 | Correct | 324 ms | 64068 KB | Output is correct |
48 | Correct | 173 ms | 57080 KB | Output is correct |
49 | Correct | 132 ms | 56936 KB | Output is correct |
50 | Correct | 300 ms | 62452 KB | Output is correct |
51 | Correct | 138 ms | 49992 KB | Output is correct |
52 | Correct | 305 ms | 65028 KB | Output is correct |
53 | Correct | 162 ms | 57864 KB | Output is correct |
54 | Correct | 150 ms | 65108 KB | Output is correct |
55 | Correct | 285 ms | 66500 KB | Output is correct |
56 | Correct | 234 ms | 70048 KB | Output is correct |
57 | Correct | 217 ms | 72260 KB | Output is correct |
58 | Correct | 239 ms | 72056 KB | Output is correct |
59 | Correct | 221 ms | 72004 KB | Output is correct |
60 | Correct | 9 ms | 14360 KB | Output is correct |
61 | Incorrect | 9 ms | 14412 KB | Output isn't correct |
62 | Halted | 0 ms | 0 KB | - |