# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
45902 | 2018-04-16T12:31:38 Z | gnoor | Fireworks (APIO16_fireworks) | C++17 | 302 ms | 122264 KB |
#include <cstdio> #include <algorithm> #include <queue> using namespace std; int par[300100]; int wgt[300100]; int mm[300100]; long long cc[300100]; priority_queue<long long> q[300100]; int main () { int n,m; scanf("%d%d",&n,&m); for (int i=2;i<=n+m;i++) { scanf("%d%d",&par[i],&wgt[i]); } //long long p,q; for (int i=n+m;i>=n+1;i--) { mm[i]=1; cc[i]=-wgt[i]; q[i].push(wgt[i]); q[i].push(wgt[i]); if (q[i].size()>q[par[i]].size()) swap(q[i],q[par[i]]); while (q[i].size()) { q[par[i]].push(q[i].top()); q[i].pop(); } mm[par[i]]+=mm[i]; cc[par[i]]+=cc[i]; } long long aa,bb; for (int i=n;i>=2;i--) { while (mm[i]>1) { cc[i]+=q[i].top(); q[i].pop(); mm[i]--; } aa=q[i].top(); q[i].pop(); bb=q[i].top(); q[i].pop(); q[i].push(aa+wgt[i]); q[i].push(bb+wgt[i]); cc[i]-=wgt[i]; if (q[i].size()>q[par[i]].size()) swap(q[i],q[par[i]]); while (q[i].size()) { q[par[i]].push(q[i].top()); q[i].pop(); } mm[par[i]]+=mm[i]; cc[par[i]]+=cc[i]; } while (mm[1]>0) { cc[1]+=q[1].top(); q[1].pop(); mm[1]--; } printf("%lld\n",cc[1]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | Output is correct |
2 | Correct | 9 ms | 9832 KB | Output is correct |
3 | Correct | 9 ms | 9900 KB | Output is correct |
4 | Correct | 9 ms | 9900 KB | Output is correct |
5 | Correct | 9 ms | 9908 KB | Output is correct |
6 | Correct | 9 ms | 9908 KB | Output is correct |
7 | Correct | 9 ms | 9908 KB | Output is correct |
8 | Correct | 9 ms | 9908 KB | Output is correct |
9 | Correct | 9 ms | 9908 KB | Output is correct |
10 | Correct | 9 ms | 9952 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 9952 KB | Output is correct |
2 | Correct | 9 ms | 9956 KB | Output is correct |
3 | Correct | 9 ms | 9956 KB | Output is correct |
4 | Correct | 11 ms | 9956 KB | Output is correct |
5 | Correct | 9 ms | 9956 KB | Output is correct |
6 | Correct | 10 ms | 9956 KB | Output is correct |
7 | Correct | 9 ms | 9956 KB | Output is correct |
8 | Correct | 9 ms | 9956 KB | Output is correct |
9 | Correct | 9 ms | 9956 KB | Output is correct |
10 | Correct | 10 ms | 9964 KB | Output is correct |
11 | Correct | 9 ms | 9980 KB | Output is correct |
12 | Correct | 9 ms | 10108 KB | Output is correct |
13 | Correct | 11 ms | 10108 KB | Output is correct |
14 | Correct | 8 ms | 10108 KB | Output is correct |
15 | Correct | 9 ms | 10108 KB | Output is correct |
16 | Correct | 9 ms | 10108 KB | Output is correct |
17 | Correct | 9 ms | 10108 KB | Output is correct |
18 | Correct | 10 ms | 10108 KB | Output is correct |
19 | Correct | 9 ms | 10108 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | Output is correct |
2 | Correct | 9 ms | 9832 KB | Output is correct |
3 | Correct | 9 ms | 9900 KB | Output is correct |
4 | Correct | 9 ms | 9900 KB | Output is correct |
5 | Correct | 9 ms | 9908 KB | Output is correct |
6 | Correct | 9 ms | 9908 KB | Output is correct |
7 | Correct | 9 ms | 9908 KB | Output is correct |
8 | Correct | 9 ms | 9908 KB | Output is correct |
9 | Correct | 9 ms | 9908 KB | Output is correct |
10 | Correct | 9 ms | 9952 KB | Output is correct |
11 | Correct | 8 ms | 9952 KB | Output is correct |
12 | Correct | 9 ms | 9956 KB | Output is correct |
13 | Correct | 9 ms | 9956 KB | Output is correct |
14 | Correct | 11 ms | 9956 KB | Output is correct |
15 | Correct | 9 ms | 9956 KB | Output is correct |
16 | Correct | 10 ms | 9956 KB | Output is correct |
17 | Correct | 9 ms | 9956 KB | Output is correct |
18 | Correct | 9 ms | 9956 KB | Output is correct |
19 | Correct | 9 ms | 9956 KB | Output is correct |
20 | Correct | 10 ms | 9964 KB | Output is correct |
21 | Correct | 9 ms | 9980 KB | Output is correct |
22 | Correct | 9 ms | 10108 KB | Output is correct |
23 | Correct | 11 ms | 10108 KB | Output is correct |
24 | Correct | 8 ms | 10108 KB | Output is correct |
25 | Correct | 9 ms | 10108 KB | Output is correct |
26 | Correct | 9 ms | 10108 KB | Output is correct |
27 | Correct | 9 ms | 10108 KB | Output is correct |
28 | Correct | 10 ms | 10108 KB | Output is correct |
29 | Correct | 9 ms | 10108 KB | Output is correct |
30 | Correct | 9 ms | 10108 KB | Output is correct |
31 | Correct | 12 ms | 10108 KB | Output is correct |
32 | Correct | 11 ms | 10112 KB | Output is correct |
33 | Correct | 13 ms | 10196 KB | Output is correct |
34 | Correct | 12 ms | 10360 KB | Output is correct |
35 | Correct | 11 ms | 10404 KB | Output is correct |
36 | Correct | 11 ms | 10544 KB | Output is correct |
37 | Correct | 15 ms | 10544 KB | Output is correct |
38 | Correct | 12 ms | 10680 KB | Output is correct |
39 | Correct | 15 ms | 10816 KB | Output is correct |
40 | Correct | 11 ms | 10816 KB | Output is correct |
41 | Correct | 11 ms | 10816 KB | Output is correct |
42 | Correct | 14 ms | 10896 KB | Output is correct |
43 | Correct | 12 ms | 11028 KB | Output is correct |
44 | Correct | 12 ms | 11232 KB | Output is correct |
45 | Correct | 12 ms | 11232 KB | Output is correct |
46 | Correct | 14 ms | 11504 KB | Output is correct |
47 | Correct | 14 ms | 11624 KB | Output is correct |
48 | Correct | 13 ms | 11624 KB | Output is correct |
49 | Correct | 13 ms | 11688 KB | Output is correct |
50 | Correct | 13 ms | 11688 KB | Output is correct |
51 | Correct | 11 ms | 11688 KB | Output is correct |
52 | Correct | 16 ms | 11768 KB | Output is correct |
53 | Correct | 12 ms | 11868 KB | Output is correct |
54 | Correct | 12 ms | 11868 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | Output is correct |
2 | Correct | 9 ms | 9832 KB | Output is correct |
3 | Correct | 9 ms | 9900 KB | Output is correct |
4 | Correct | 9 ms | 9900 KB | Output is correct |
5 | Correct | 9 ms | 9908 KB | Output is correct |
6 | Correct | 9 ms | 9908 KB | Output is correct |
7 | Correct | 9 ms | 9908 KB | Output is correct |
8 | Correct | 9 ms | 9908 KB | Output is correct |
9 | Correct | 9 ms | 9908 KB | Output is correct |
10 | Correct | 9 ms | 9952 KB | Output is correct |
11 | Correct | 8 ms | 9952 KB | Output is correct |
12 | Correct | 9 ms | 9956 KB | Output is correct |
13 | Correct | 9 ms | 9956 KB | Output is correct |
14 | Correct | 11 ms | 9956 KB | Output is correct |
15 | Correct | 9 ms | 9956 KB | Output is correct |
16 | Correct | 10 ms | 9956 KB | Output is correct |
17 | Correct | 9 ms | 9956 KB | Output is correct |
18 | Correct | 9 ms | 9956 KB | Output is correct |
19 | Correct | 9 ms | 9956 KB | Output is correct |
20 | Correct | 10 ms | 9964 KB | Output is correct |
21 | Correct | 9 ms | 9980 KB | Output is correct |
22 | Correct | 9 ms | 10108 KB | Output is correct |
23 | Correct | 11 ms | 10108 KB | Output is correct |
24 | Correct | 8 ms | 10108 KB | Output is correct |
25 | Correct | 9 ms | 10108 KB | Output is correct |
26 | Correct | 9 ms | 10108 KB | Output is correct |
27 | Correct | 9 ms | 10108 KB | Output is correct |
28 | Correct | 10 ms | 10108 KB | Output is correct |
29 | Correct | 9 ms | 10108 KB | Output is correct |
30 | Correct | 9 ms | 10108 KB | Output is correct |
31 | Correct | 12 ms | 10108 KB | Output is correct |
32 | Correct | 11 ms | 10112 KB | Output is correct |
33 | Correct | 13 ms | 10196 KB | Output is correct |
34 | Correct | 12 ms | 10360 KB | Output is correct |
35 | Correct | 11 ms | 10404 KB | Output is correct |
36 | Correct | 11 ms | 10544 KB | Output is correct |
37 | Correct | 15 ms | 10544 KB | Output is correct |
38 | Correct | 12 ms | 10680 KB | Output is correct |
39 | Correct | 15 ms | 10816 KB | Output is correct |
40 | Correct | 11 ms | 10816 KB | Output is correct |
41 | Correct | 11 ms | 10816 KB | Output is correct |
42 | Correct | 14 ms | 10896 KB | Output is correct |
43 | Correct | 12 ms | 11028 KB | Output is correct |
44 | Correct | 12 ms | 11232 KB | Output is correct |
45 | Correct | 12 ms | 11232 KB | Output is correct |
46 | Correct | 14 ms | 11504 KB | Output is correct |
47 | Correct | 14 ms | 11624 KB | Output is correct |
48 | Correct | 13 ms | 11624 KB | Output is correct |
49 | Correct | 13 ms | 11688 KB | Output is correct |
50 | Correct | 13 ms | 11688 KB | Output is correct |
51 | Correct | 11 ms | 11688 KB | Output is correct |
52 | Correct | 16 ms | 11768 KB | Output is correct |
53 | Correct | 12 ms | 11868 KB | Output is correct |
54 | Correct | 12 ms | 11868 KB | Output is correct |
55 | Correct | 17 ms | 12420 KB | Output is correct |
56 | Correct | 40 ms | 15428 KB | Output is correct |
57 | Correct | 90 ms | 18580 KB | Output is correct |
58 | Correct | 80 ms | 21712 KB | Output is correct |
59 | Correct | 140 ms | 25656 KB | Output is correct |
60 | Correct | 172 ms | 30296 KB | Output is correct |
61 | Correct | 161 ms | 35244 KB | Output is correct |
62 | Correct | 170 ms | 39800 KB | Output is correct |
63 | Correct | 211 ms | 46504 KB | Output is correct |
64 | Correct | 216 ms | 51512 KB | Output is correct |
65 | Correct | 103 ms | 51512 KB | Output is correct |
66 | Correct | 101 ms | 51512 KB | Output is correct |
67 | Correct | 100 ms | 56248 KB | Output is correct |
68 | Correct | 174 ms | 67820 KB | Output is correct |
69 | Correct | 200 ms | 73296 KB | Output is correct |
70 | Correct | 210 ms | 78088 KB | Output is correct |
71 | Correct | 302 ms | 97716 KB | Output is correct |
72 | Correct | 242 ms | 101976 KB | Output is correct |
73 | Correct | 221 ms | 102652 KB | Output is correct |
74 | Correct | 218 ms | 107180 KB | Output is correct |
75 | Correct | 211 ms | 109632 KB | Output is correct |
76 | Correct | 217 ms | 113432 KB | Output is correct |
77 | Correct | 227 ms | 116760 KB | Output is correct |
78 | Correct | 229 ms | 120556 KB | Output is correct |
79 | Correct | 218 ms | 122264 KB | Output is correct |