# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
329221 | 2020-11-19T22:56:35 Z | Nirjhor | Fireworks (APIO16_fireworks) | C++17 | 255 ms | 61284 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 300010; int n, m, p[N]; vector <int> g[N]; ll w[N], a[N], b[N]; priority_queue <ll> *pq[N]; int main() { cin >> m >> n; n += m; for (int i = 2; i <= n; ++i) { scanf("%d %lld", p + i, w + i); g[p[i]].emplace_back(i); } for (int i = m + 1; i <= n; ++i) { a[i] = 1, b[i] = -w[i]; pq[i] = new priority_queue <ll> (); pq[i] -> emplace(w[i]); pq[i] -> emplace(w[i]); } for (int i = m; i >= 1; --i) { pq[i] = new priority_queue <ll> (); for (int j : g[i]) { if (pq[j] -> size() > pq[i] -> size()) swap(pq[i], pq[j]); while (!(pq[j] -> empty())) pq[i] -> emplace(pq[j] -> top()), pq[j] -> pop(); a[i] += a[j], b[i] += b[j]; } while (a[i] > 1) b[i] += pq[i] -> top(), --a[i], pq[i] -> pop(); b[i] -= w[i]; ll one = pq[i] -> top(); pq[i] -> pop(); ll zero = pq[i] -> top(); pq[i] -> pop(); pq[i] -> emplace(one + w[i]); pq[i] -> emplace(zero + w[i]); } cout << a[1] * pq[1] -> top() + b[1] << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7404 KB | Output is correct |
2 | Correct | 5 ms | 7404 KB | Output is correct |
3 | Correct | 5 ms | 7404 KB | Output is correct |
4 | Correct | 5 ms | 7404 KB | Output is correct |
5 | Correct | 5 ms | 7404 KB | Output is correct |
6 | Correct | 6 ms | 7404 KB | Output is correct |
7 | Correct | 5 ms | 7404 KB | Output is correct |
8 | Correct | 6 ms | 7404 KB | Output is correct |
9 | Correct | 5 ms | 7404 KB | Output is correct |
10 | Correct | 5 ms | 7404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7404 KB | Output is correct |
2 | Correct | 5 ms | 7404 KB | Output is correct |
3 | Correct | 5 ms | 7404 KB | Output is correct |
4 | Correct | 5 ms | 7404 KB | Output is correct |
5 | Correct | 5 ms | 7424 KB | Output is correct |
6 | Correct | 5 ms | 7404 KB | Output is correct |
7 | Correct | 5 ms | 7404 KB | Output is correct |
8 | Correct | 5 ms | 7404 KB | Output is correct |
9 | Correct | 5 ms | 7532 KB | Output is correct |
10 | Correct | 5 ms | 7404 KB | Output is correct |
11 | Correct | 5 ms | 7404 KB | Output is correct |
12 | Correct | 7 ms | 7404 KB | Output is correct |
13 | Correct | 5 ms | 7404 KB | Output is correct |
14 | Correct | 5 ms | 7404 KB | Output is correct |
15 | Correct | 5 ms | 7404 KB | Output is correct |
16 | Correct | 5 ms | 7404 KB | Output is correct |
17 | Correct | 5 ms | 7404 KB | Output is correct |
18 | Correct | 5 ms | 7404 KB | Output is correct |
19 | Correct | 5 ms | 7404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7404 KB | Output is correct |
2 | Correct | 5 ms | 7404 KB | Output is correct |
3 | Correct | 5 ms | 7404 KB | Output is correct |
4 | Correct | 5 ms | 7404 KB | Output is correct |
5 | Correct | 5 ms | 7404 KB | Output is correct |
6 | Correct | 6 ms | 7404 KB | Output is correct |
7 | Correct | 5 ms | 7404 KB | Output is correct |
8 | Correct | 6 ms | 7404 KB | Output is correct |
9 | Correct | 5 ms | 7404 KB | Output is correct |
10 | Correct | 5 ms | 7404 KB | Output is correct |
11 | Correct | 5 ms | 7404 KB | Output is correct |
12 | Correct | 5 ms | 7404 KB | Output is correct |
13 | Correct | 5 ms | 7404 KB | Output is correct |
14 | Correct | 5 ms | 7404 KB | Output is correct |
15 | Correct | 5 ms | 7424 KB | Output is correct |
16 | Correct | 5 ms | 7404 KB | Output is correct |
17 | Correct | 5 ms | 7404 KB | Output is correct |
18 | Correct | 5 ms | 7404 KB | Output is correct |
19 | Correct | 5 ms | 7532 KB | Output is correct |
20 | Correct | 5 ms | 7404 KB | Output is correct |
21 | Correct | 5 ms | 7404 KB | Output is correct |
22 | Correct | 7 ms | 7404 KB | Output is correct |
23 | Correct | 5 ms | 7404 KB | Output is correct |
24 | Correct | 5 ms | 7404 KB | Output is correct |
25 | Correct | 5 ms | 7404 KB | Output is correct |
26 | Correct | 5 ms | 7404 KB | Output is correct |
27 | Correct | 5 ms | 7404 KB | Output is correct |
28 | Correct | 5 ms | 7404 KB | Output is correct |
29 | Correct | 5 ms | 7404 KB | Output is correct |
30 | Correct | 5 ms | 7404 KB | Output is correct |
31 | Correct | 6 ms | 7532 KB | Output is correct |
32 | Correct | 6 ms | 7660 KB | Output is correct |
33 | Correct | 6 ms | 7660 KB | Output is correct |
34 | Correct | 7 ms | 7916 KB | Output is correct |
35 | Correct | 9 ms | 7916 KB | Output is correct |
36 | Correct | 7 ms | 8044 KB | Output is correct |
37 | Correct | 8 ms | 8044 KB | Output is correct |
38 | Correct | 8 ms | 8172 KB | Output is correct |
39 | Correct | 8 ms | 8172 KB | Output is correct |
40 | Correct | 7 ms | 8044 KB | Output is correct |
41 | Correct | 10 ms | 8044 KB | Output is correct |
42 | Correct | 7 ms | 8044 KB | Output is correct |
43 | Correct | 8 ms | 8044 KB | Output is correct |
44 | Correct | 8 ms | 8044 KB | Output is correct |
45 | Correct | 8 ms | 8044 KB | Output is correct |
46 | Correct | 8 ms | 8300 KB | Output is correct |
47 | Correct | 8 ms | 8300 KB | Output is correct |
48 | Correct | 7 ms | 8172 KB | Output is correct |
49 | Correct | 8 ms | 8172 KB | Output is correct |
50 | Correct | 8 ms | 8044 KB | Output is correct |
51 | Correct | 8 ms | 8044 KB | Output is correct |
52 | Correct | 8 ms | 8172 KB | Output is correct |
53 | Correct | 8 ms | 8172 KB | Output is correct |
54 | Correct | 8 ms | 8300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7404 KB | Output is correct |
2 | Correct | 5 ms | 7404 KB | Output is correct |
3 | Correct | 5 ms | 7404 KB | Output is correct |
4 | Correct | 5 ms | 7404 KB | Output is correct |
5 | Correct | 5 ms | 7404 KB | Output is correct |
6 | Correct | 6 ms | 7404 KB | Output is correct |
7 | Correct | 5 ms | 7404 KB | Output is correct |
8 | Correct | 6 ms | 7404 KB | Output is correct |
9 | Correct | 5 ms | 7404 KB | Output is correct |
10 | Correct | 5 ms | 7404 KB | Output is correct |
11 | Correct | 5 ms | 7404 KB | Output is correct |
12 | Correct | 5 ms | 7404 KB | Output is correct |
13 | Correct | 5 ms | 7404 KB | Output is correct |
14 | Correct | 5 ms | 7404 KB | Output is correct |
15 | Correct | 5 ms | 7424 KB | Output is correct |
16 | Correct | 5 ms | 7404 KB | Output is correct |
17 | Correct | 5 ms | 7404 KB | Output is correct |
18 | Correct | 5 ms | 7404 KB | Output is correct |
19 | Correct | 5 ms | 7532 KB | Output is correct |
20 | Correct | 5 ms | 7404 KB | Output is correct |
21 | Correct | 5 ms | 7404 KB | Output is correct |
22 | Correct | 7 ms | 7404 KB | Output is correct |
23 | Correct | 5 ms | 7404 KB | Output is correct |
24 | Correct | 5 ms | 7404 KB | Output is correct |
25 | Correct | 5 ms | 7404 KB | Output is correct |
26 | Correct | 5 ms | 7404 KB | Output is correct |
27 | Correct | 5 ms | 7404 KB | Output is correct |
28 | Correct | 5 ms | 7404 KB | Output is correct |
29 | Correct | 5 ms | 7404 KB | Output is correct |
30 | Correct | 5 ms | 7404 KB | Output is correct |
31 | Correct | 6 ms | 7532 KB | Output is correct |
32 | Correct | 6 ms | 7660 KB | Output is correct |
33 | Correct | 6 ms | 7660 KB | Output is correct |
34 | Correct | 7 ms | 7916 KB | Output is correct |
35 | Correct | 9 ms | 7916 KB | Output is correct |
36 | Correct | 7 ms | 8044 KB | Output is correct |
37 | Correct | 8 ms | 8044 KB | Output is correct |
38 | Correct | 8 ms | 8172 KB | Output is correct |
39 | Correct | 8 ms | 8172 KB | Output is correct |
40 | Correct | 7 ms | 8044 KB | Output is correct |
41 | Correct | 10 ms | 8044 KB | Output is correct |
42 | Correct | 7 ms | 8044 KB | Output is correct |
43 | Correct | 8 ms | 8044 KB | Output is correct |
44 | Correct | 8 ms | 8044 KB | Output is correct |
45 | Correct | 8 ms | 8044 KB | Output is correct |
46 | Correct | 8 ms | 8300 KB | Output is correct |
47 | Correct | 8 ms | 8300 KB | Output is correct |
48 | Correct | 7 ms | 8172 KB | Output is correct |
49 | Correct | 8 ms | 8172 KB | Output is correct |
50 | Correct | 8 ms | 8044 KB | Output is correct |
51 | Correct | 8 ms | 8044 KB | Output is correct |
52 | Correct | 8 ms | 8172 KB | Output is correct |
53 | Correct | 8 ms | 8172 KB | Output is correct |
54 | Correct | 8 ms | 8300 KB | Output is correct |
55 | Correct | 13 ms | 9324 KB | Output is correct |
56 | Correct | 40 ms | 14828 KB | Output is correct |
57 | Correct | 72 ms | 19968 KB | Output is correct |
58 | Correct | 88 ms | 23528 KB | Output is correct |
59 | Correct | 124 ms | 28772 KB | Output is correct |
60 | Correct | 158 ms | 34104 KB | Output is correct |
61 | Correct | 176 ms | 37988 KB | Output is correct |
62 | Correct | 200 ms | 40928 KB | Output is correct |
63 | Correct | 251 ms | 47472 KB | Output is correct |
64 | Correct | 255 ms | 49636 KB | Output is correct |
65 | Correct | 130 ms | 46316 KB | Output is correct |
66 | Correct | 132 ms | 46372 KB | Output is correct |
67 | Correct | 131 ms | 46436 KB | Output is correct |
68 | Correct | 179 ms | 47452 KB | Output is correct |
69 | Correct | 212 ms | 47452 KB | Output is correct |
70 | Correct | 211 ms | 47472 KB | Output is correct |
71 | Correct | 213 ms | 61284 KB | Output is correct |
72 | Correct | 210 ms | 61020 KB | Output is correct |
73 | Correct | 186 ms | 57180 KB | Output is correct |
74 | Correct | 185 ms | 57516 KB | Output is correct |
75 | Correct | 186 ms | 56280 KB | Output is correct |
76 | Correct | 184 ms | 56352 KB | Output is correct |
77 | Correct | 194 ms | 55260 KB | Output is correct |
78 | Correct | 192 ms | 54628 KB | Output is correct |
79 | Correct | 180 ms | 54492 KB | Output is correct |