# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163995 | 2019-11-16T15:11:08 Z | Akashi | Fireworks (APIO16_fireworks) | C++14 | 264 ms | 51112 KB |
#include <bits/stdc++.h> using namespace std; struct graph{ long long a, b; priority_queue <long long> *pq; graph operator+(graph aux){ graph sum; sum.a = a + aux.a; sum.b = b + aux.b; if(pq->size() < aux.pq->size()){ sum.pq = aux.pq; while(!pq->empty()){ sum.pq->push(pq->top()); pq->pop(); } } else{ sum.pq = pq; while(!aux.pq->empty()){ sum.pq->push(aux.pq->top()); aux.pq->pop(); } } return sum; } }; graph d[300005]; int n, m; int P[300005], C[300005]; int main() { // freopen("1.in", "r", stdin); scanf("%d%d", &n, &m); for(int i = 2; i <= n + m ; ++i) scanf("%d%d", &P[i], &C[i]); for(int i = 1; i <= n + m ; ++i) d[i].pq = new priority_queue <long long>; for(int i = n + 1; i <= n + m ; ++i){ d[i].a = 1; d[i].b = -C[i]; d[i].pq->push(C[i]); d[i].pq->push(C[i]); d[P[i]] = d[P[i]] + d[i]; } for(int i = n; i > 1 ; --i){ while(d[i].a > 1){ --d[i].a; d[i].b += d[i].pq->top(); d[i].pq->pop(); } long long x, y; x = d[i].pq->top(); d[i].pq->pop(); y = d[i].pq->top(); d[i].pq->pop(); d[i].pq->push(x + C[i]); d[i].pq->push(y + C[i]); d[i].b -= C[i]; d[P[i]] = d[P[i]] + d[i]; } while(d[1].a > 0){ --d[1].a; d[1].b += d[1].pq->top(); d[1].pq->pop(); } printf("%lld", d[1].b); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 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 | 376 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 | 348 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 | 380 KB | Output is correct |
10 | Correct | 2 ms | 396 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 | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 380 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 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 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 | 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 | 376 KB | Output is correct |
15 | Correct | 2 ms | 348 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 |
20 | Correct | 2 ms | 396 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 | 376 KB | Output is correct |
25 | Correct | 2 ms | 376 KB | Output is correct |
26 | Correct | 2 ms | 380 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 | 376 KB | Output is correct |
30 | Correct | 2 ms | 376 KB | Output is correct |
31 | Correct | 3 ms | 504 KB | Output is correct |
32 | Correct | 3 ms | 504 KB | Output is correct |
33 | Correct | 4 ms | 632 KB | Output is correct |
34 | Correct | 4 ms | 760 KB | Output is correct |
35 | Correct | 4 ms | 760 KB | Output is correct |
36 | Correct | 5 ms | 888 KB | Output is correct |
37 | Correct | 5 ms | 888 KB | Output is correct |
38 | Correct | 5 ms | 1004 KB | Output is correct |
39 | Correct | 5 ms | 1016 KB | Output is correct |
40 | Correct | 4 ms | 888 KB | Output is correct |
41 | Correct | 17 ms | 760 KB | Output is correct |
42 | Correct | 4 ms | 760 KB | Output is correct |
43 | Correct | 4 ms | 888 KB | Output is correct |
44 | Correct | 5 ms | 924 KB | Output is correct |
45 | Correct | 5 ms | 1016 KB | Output is correct |
46 | Correct | 6 ms | 1144 KB | Output is correct |
47 | Correct | 6 ms | 1144 KB | Output is correct |
48 | Correct | 5 ms | 1016 KB | Output is correct |
49 | Correct | 6 ms | 1144 KB | Output is correct |
50 | Correct | 5 ms | 888 KB | Output is correct |
51 | Correct | 5 ms | 1016 KB | Output is correct |
52 | Correct | 5 ms | 1016 KB | Output is correct |
53 | Correct | 5 ms | 1016 KB | Output is correct |
54 | Correct | 6 ms | 1144 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 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 | 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 | 376 KB | Output is correct |
15 | Correct | 2 ms | 348 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 |
20 | Correct | 2 ms | 396 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 | 376 KB | Output is correct |
25 | Correct | 2 ms | 376 KB | Output is correct |
26 | Correct | 2 ms | 380 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 | 376 KB | Output is correct |
30 | Correct | 2 ms | 376 KB | Output is correct |
31 | Correct | 3 ms | 504 KB | Output is correct |
32 | Correct | 3 ms | 504 KB | Output is correct |
33 | Correct | 4 ms | 632 KB | Output is correct |
34 | Correct | 4 ms | 760 KB | Output is correct |
35 | Correct | 4 ms | 760 KB | Output is correct |
36 | Correct | 5 ms | 888 KB | Output is correct |
37 | Correct | 5 ms | 888 KB | Output is correct |
38 | Correct | 5 ms | 1004 KB | Output is correct |
39 | Correct | 5 ms | 1016 KB | Output is correct |
40 | Correct | 4 ms | 888 KB | Output is correct |
41 | Correct | 17 ms | 760 KB | Output is correct |
42 | Correct | 4 ms | 760 KB | Output is correct |
43 | Correct | 4 ms | 888 KB | Output is correct |
44 | Correct | 5 ms | 924 KB | Output is correct |
45 | Correct | 5 ms | 1016 KB | Output is correct |
46 | Correct | 6 ms | 1144 KB | Output is correct |
47 | Correct | 6 ms | 1144 KB | Output is correct |
48 | Correct | 5 ms | 1016 KB | Output is correct |
49 | Correct | 6 ms | 1144 KB | Output is correct |
50 | Correct | 5 ms | 888 KB | Output is correct |
51 | Correct | 5 ms | 1016 KB | Output is correct |
52 | Correct | 5 ms | 1016 KB | Output is correct |
53 | Correct | 5 ms | 1016 KB | Output is correct |
54 | Correct | 6 ms | 1144 KB | Output is correct |
55 | Correct | 10 ms | 2040 KB | Output is correct |
56 | Correct | 36 ms | 6848 KB | Output is correct |
57 | Correct | 62 ms | 11412 KB | Output is correct |
58 | Correct | 81 ms | 14480 KB | Output is correct |
59 | Correct | 106 ms | 19056 KB | Output is correct |
60 | Correct | 143 ms | 23668 KB | Output is correct |
61 | Correct | 162 ms | 27120 KB | Output is correct |
62 | Correct | 180 ms | 29732 KB | Output is correct |
63 | Correct | 223 ms | 35428 KB | Output is correct |
64 | Correct | 229 ms | 37228 KB | Output is correct |
65 | Correct | 116 ms | 28792 KB | Output is correct |
66 | Correct | 116 ms | 28672 KB | Output is correct |
67 | Correct | 116 ms | 28792 KB | Output is correct |
68 | Correct | 186 ms | 35560 KB | Output is correct |
69 | Correct | 210 ms | 36056 KB | Output is correct |
70 | Correct | 210 ms | 36076 KB | Output is correct |
71 | Correct | 252 ms | 50952 KB | Output is correct |
72 | Correct | 264 ms | 51112 KB | Output is correct |
73 | Correct | 219 ms | 47624 KB | Output is correct |
74 | Correct | 227 ms | 47900 KB | Output is correct |
75 | Correct | 220 ms | 46256 KB | Output is correct |
76 | Correct | 221 ms | 46376 KB | Output is correct |
77 | Correct | 230 ms | 45516 KB | Output is correct |
78 | Correct | 233 ms | 44928 KB | Output is correct |
79 | Correct | 219 ms | 43740 KB | Output is correct |