# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
122884 | 2019-06-29T12:57:59 Z | diamond_duke | Fireworks (APIO16_fireworks) | C++11 | 469 ms | 21368 KB |
#include <algorithm> #include <cstdio> using ll = long long; int lson[1200005], rson[1200005], dep[1200005], t_cnt; ll val[1200005]; int merge(int u, int v) { if (!u || !v) return u | v; if (val[u] < val[v]) std::swap(u, v); rson[u] = merge(rson[u], v); if (dep[lson[u]] < dep[rson[u]]) std::swap(lson[u], rson[u]); dep[u] = rson[u] ? dep[rson[u]] + 1 : 0; return u; } inline int new_node(ll x) { val[++t_cnt] = x; return t_cnt; } void pop(int &u) { u = merge(lson[u], rson[u]); } int fa[600005], faw[600005], son[600005], rt[600005]; int main() { int n, m; scanf("%d%d", &n, &m); ll ans = 0; for (int i = 1; i < n + m; i++) { scanf("%d%d", fa + i, faw + i); son[--fa[i]]++; ans += faw[i]; } for (int u = n + m - 1; u; u--) { ll x = 0, y = 0; if (u < n) { while (--son[u]) pop(rt[u]); y = val[rt[u]]; pop(rt[u]); x = val[rt[u]]; pop(rt[u]); } rt[u] = merge(rt[u], merge(new_node(x + faw[u]), new_node(y + faw[u]))); rt[fa[u]] = merge(rt[fa[u]], rt[u]); } while (son[0]--) pop(rt[0]); while (rt[0]) { ans -= val[rt[0]]; pop(rt[0]); } printf("%lld\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 504 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 404 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 504 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 504 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 2 ms | 376 KB | Output is correct |
23 | Correct | 2 ms | 376 KB | Output is correct |
24 | Correct | 2 ms | 404 KB | Output is correct |
25 | Correct | 2 ms | 376 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Correct | 2 ms | 376 KB | Output is correct |
28 | Correct | 2 ms | 376 KB | Output is correct |
29 | Correct | 2 ms | 380 KB | Output is correct |
30 | Correct | 2 ms | 376 KB | Output is correct |
31 | Correct | 2 ms | 376 KB | Output is correct |
32 | Correct | 2 ms | 504 KB | Output is correct |
33 | Correct | 3 ms | 504 KB | Output is correct |
34 | Correct | 3 ms | 636 KB | Output is correct |
35 | Correct | 4 ms | 632 KB | Output is correct |
36 | Correct | 4 ms | 632 KB | Output is correct |
37 | Correct | 4 ms | 760 KB | Output is correct |
38 | Correct | 4 ms | 760 KB | Output is correct |
39 | Correct | 4 ms | 760 KB | Output is correct |
40 | Correct | 3 ms | 632 KB | Output is correct |
41 | Correct | 3 ms | 632 KB | Output is correct |
42 | Correct | 3 ms | 632 KB | Output is correct |
43 | Correct | 4 ms | 632 KB | Output is correct |
44 | Correct | 4 ms | 660 KB | Output is correct |
45 | Correct | 4 ms | 632 KB | Output is correct |
46 | Correct | 5 ms | 632 KB | Output is correct |
47 | Correct | 5 ms | 760 KB | Output is correct |
48 | Correct | 5 ms | 632 KB | Output is correct |
49 | Correct | 5 ms | 760 KB | Output is correct |
50 | Correct | 5 ms | 632 KB | Output is correct |
51 | Correct | 5 ms | 632 KB | Output is correct |
52 | Correct | 5 ms | 632 KB | Output is correct |
53 | Correct | 5 ms | 632 KB | Output is correct |
54 | Correct | 6 ms | 760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 504 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 504 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 2 ms | 376 KB | Output is correct |
23 | Correct | 2 ms | 376 KB | Output is correct |
24 | Correct | 2 ms | 404 KB | Output is correct |
25 | Correct | 2 ms | 376 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Correct | 2 ms | 376 KB | Output is correct |
28 | Correct | 2 ms | 376 KB | Output is correct |
29 | Correct | 2 ms | 380 KB | Output is correct |
30 | Correct | 2 ms | 376 KB | Output is correct |
31 | Correct | 2 ms | 376 KB | Output is correct |
32 | Correct | 2 ms | 504 KB | Output is correct |
33 | Correct | 3 ms | 504 KB | Output is correct |
34 | Correct | 3 ms | 636 KB | Output is correct |
35 | Correct | 4 ms | 632 KB | Output is correct |
36 | Correct | 4 ms | 632 KB | Output is correct |
37 | Correct | 4 ms | 760 KB | Output is correct |
38 | Correct | 4 ms | 760 KB | Output is correct |
39 | Correct | 4 ms | 760 KB | Output is correct |
40 | Correct | 3 ms | 632 KB | Output is correct |
41 | Correct | 3 ms | 632 KB | Output is correct |
42 | Correct | 3 ms | 632 KB | Output is correct |
43 | Correct | 4 ms | 632 KB | Output is correct |
44 | Correct | 4 ms | 660 KB | Output is correct |
45 | Correct | 4 ms | 632 KB | Output is correct |
46 | Correct | 5 ms | 632 KB | Output is correct |
47 | Correct | 5 ms | 760 KB | Output is correct |
48 | Correct | 5 ms | 632 KB | Output is correct |
49 | Correct | 5 ms | 760 KB | Output is correct |
50 | Correct | 5 ms | 632 KB | Output is correct |
51 | Correct | 5 ms | 632 KB | Output is correct |
52 | Correct | 5 ms | 632 KB | Output is correct |
53 | Correct | 5 ms | 632 KB | Output is correct |
54 | Correct | 6 ms | 760 KB | Output is correct |
55 | Correct | 8 ms | 1272 KB | Output is correct |
56 | Correct | 27 ms | 3704 KB | Output is correct |
57 | Correct | 46 ms | 6136 KB | Output is correct |
58 | Correct | 59 ms | 7800 KB | Output is correct |
59 | Correct | 81 ms | 10232 KB | Output is correct |
60 | Correct | 117 ms | 12540 KB | Output is correct |
61 | Correct | 117 ms | 14328 KB | Output is correct |
62 | Correct | 147 ms | 15828 KB | Output is correct |
63 | Correct | 161 ms | 18812 KB | Output is correct |
64 | Correct | 207 ms | 19832 KB | Output is correct |
65 | Correct | 96 ms | 19320 KB | Output is correct |
66 | Correct | 92 ms | 19420 KB | Output is correct |
67 | Correct | 94 ms | 21368 KB | Output is correct |
68 | Correct | 179 ms | 20984 KB | Output is correct |
69 | Correct | 190 ms | 20984 KB | Output is correct |
70 | Correct | 192 ms | 20840 KB | Output is correct |
71 | Correct | 305 ms | 19960 KB | Output is correct |
72 | Correct | 292 ms | 19900 KB | Output is correct |
73 | Correct | 323 ms | 19704 KB | Output is correct |
74 | Correct | 326 ms | 19832 KB | Output is correct |
75 | Correct | 331 ms | 19340 KB | Output is correct |
76 | Correct | 327 ms | 19576 KB | Output is correct |
77 | Correct | 369 ms | 19464 KB | Output is correct |
78 | Correct | 379 ms | 19192 KB | Output is correct |
79 | Correct | 469 ms | 19244 KB | Output is correct |