# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
111405 | 2019-05-15T07:28:34 Z | diamond_duke | Fireworks (APIO16_fireworks) | C++11 | 464 ms | 19372 KB |
#include <algorithm> #include <cstdio> using ll = long long; int lson[1200005], rson[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); std::swap(lson[u], rson[u]); 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], deg[600005], rt[600005]; int main() { // freopen("uoj-205.in", "r", stdin); 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); deg[--fa[i]]++; ans += faw[i]; } for (int u = n + m - 1; u; u--) { ll l = 0, r = 0; if (u < n) { while (--deg[u]) pop(rt[u]); r = val[rt[u]]; pop(rt[u]); l = val[rt[u]]; pop(rt[u]); } rt[u] = merge(rt[u], merge(new_node(l + faw[u]), new_node(r + faw[u]))); rt[fa[u]] = merge(rt[fa[u]], rt[u]); } while (deg[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 | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 3 ms | 384 KB | Output is correct |
16 | Correct | 3 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 3 ms | 384 KB | Output is correct |
19 | Correct | 3 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 3 ms | 384 KB | Output is correct |
26 | Correct | 3 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 3 ms | 384 KB | Output is correct |
29 | Correct | 3 ms | 384 KB | Output is correct |
30 | Correct | 2 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 3 ms | 512 KB | Output is correct |
34 | Correct | 3 ms | 512 KB | Output is correct |
35 | Correct | 4 ms | 512 KB | Output is correct |
36 | Correct | 3 ms | 512 KB | Output is correct |
37 | Correct | 4 ms | 640 KB | Output is correct |
38 | Correct | 4 ms | 640 KB | Output is correct |
39 | Correct | 3 ms | 640 KB | Output is correct |
40 | Correct | 5 ms | 640 KB | Output is correct |
41 | Correct | 4 ms | 640 KB | Output is correct |
42 | Correct | 4 ms | 640 KB | Output is correct |
43 | Correct | 4 ms | 640 KB | Output is correct |
44 | Correct | 5 ms | 512 KB | Output is correct |
45 | Correct | 4 ms | 512 KB | Output is correct |
46 | Correct | 5 ms | 512 KB | Output is correct |
47 | Correct | 6 ms | 512 KB | Output is correct |
48 | Correct | 5 ms | 512 KB | Output is correct |
49 | Correct | 6 ms | 512 KB | Output is correct |
50 | Correct | 4 ms | 512 KB | Output is correct |
51 | Correct | 4 ms | 512 KB | Output is correct |
52 | Correct | 4 ms | 512 KB | Output is correct |
53 | Correct | 5 ms | 512 KB | Output is correct |
54 | Correct | 6 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 3 ms | 384 KB | Output is correct |
26 | Correct | 3 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 3 ms | 384 KB | Output is correct |
29 | Correct | 3 ms | 384 KB | Output is correct |
30 | Correct | 2 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 3 ms | 512 KB | Output is correct |
34 | Correct | 3 ms | 512 KB | Output is correct |
35 | Correct | 4 ms | 512 KB | Output is correct |
36 | Correct | 3 ms | 512 KB | Output is correct |
37 | Correct | 4 ms | 640 KB | Output is correct |
38 | Correct | 4 ms | 640 KB | Output is correct |
39 | Correct | 3 ms | 640 KB | Output is correct |
40 | Correct | 5 ms | 640 KB | Output is correct |
41 | Correct | 4 ms | 640 KB | Output is correct |
42 | Correct | 4 ms | 640 KB | Output is correct |
43 | Correct | 4 ms | 640 KB | Output is correct |
44 | Correct | 5 ms | 512 KB | Output is correct |
45 | Correct | 4 ms | 512 KB | Output is correct |
46 | Correct | 5 ms | 512 KB | Output is correct |
47 | Correct | 6 ms | 512 KB | Output is correct |
48 | Correct | 5 ms | 512 KB | Output is correct |
49 | Correct | 6 ms | 512 KB | Output is correct |
50 | Correct | 4 ms | 512 KB | Output is correct |
51 | Correct | 4 ms | 512 KB | Output is correct |
52 | Correct | 4 ms | 512 KB | Output is correct |
53 | Correct | 5 ms | 512 KB | Output is correct |
54 | Correct | 6 ms | 512 KB | Output is correct |
55 | Correct | 10 ms | 1024 KB | Output is correct |
56 | Correct | 25 ms | 2680 KB | Output is correct |
57 | Correct | 45 ms | 4220 KB | Output is correct |
58 | Correct | 65 ms | 5188 KB | Output is correct |
59 | Correct | 102 ms | 9252 KB | Output is correct |
60 | Correct | 109 ms | 11256 KB | Output is correct |
61 | Correct | 123 ms | 12780 KB | Output is correct |
62 | Correct | 144 ms | 14104 KB | Output is correct |
63 | Correct | 150 ms | 16800 KB | Output is correct |
64 | Correct | 152 ms | 17656 KB | Output is correct |
65 | Correct | 104 ms | 19372 KB | Output is correct |
66 | Correct | 77 ms | 19320 KB | Output is correct |
67 | Correct | 102 ms | 19320 KB | Output is correct |
68 | Correct | 152 ms | 18552 KB | Output is correct |
69 | Correct | 164 ms | 18552 KB | Output is correct |
70 | Correct | 176 ms | 18552 KB | Output is correct |
71 | Correct | 271 ms | 17656 KB | Output is correct |
72 | Correct | 274 ms | 17656 KB | Output is correct |
73 | Correct | 276 ms | 17272 KB | Output is correct |
74 | Correct | 265 ms | 17400 KB | Output is correct |
75 | Correct | 311 ms | 17116 KB | Output is correct |
76 | Correct | 291 ms | 17224 KB | Output is correct |
77 | Correct | 256 ms | 17144 KB | Output is correct |
78 | Correct | 263 ms | 16988 KB | Output is correct |
79 | Correct | 464 ms | 16888 KB | Output is correct |