Submission #386040

# Submission time Handle Problem Language Result Execution time Memory
386040 2021-04-05T13:22:46 Z MiricaMatei Fireworks (APIO16_fireworks) C++14
100 / 100
231 ms 51872 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN =  300005;

vector<int>G[MAXN];
priority_queue<long long>pq[MAXN];
long long a[MAXN], b[MAXN];
int c[MAXN];

int main() {

  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n + m; ++i) {
    int p;
    scanf("%d%d", &p, &c[i]);
    G[p].push_back(i);
  }

  for (int i = n + 1; i <= n + m; ++i) {
    pq[i].push(c[i]);
    pq[i].push(c[i]);
    a[i] = 1;
    b[i] = -c[i];
  }

  for (int i = n; i >= 1; --i) {
    for (auto it:G[i]) {
      if (pq[i].size() < pq[it].size())
        swap(pq[i], pq[it]);
      while (!pq[it].empty()) {
        pq[i].push(pq[it].top());
        pq[it].pop();
      }
      a[i] += a[it];
      b[i] += b[it];
    }
    while (a[i] > 1) {
      long long x = pq[i].top();
      a[i]--;
      b[i] += x;
      pq[i].pop();
    }

    b[i] -= c[i];
    long long x1 = pq[i].top();
    pq[i].pop();
    long long x0 = pq[i].top();
    pq[i].pop();
    x1 += c[i];
    x0 += c[i];
    pq[i].push(x0);
    pq[i].push(x1);
  }

  while (a[1] > 0) {
    long long x = pq[1].top();
    a[1]--;
    b[1] += x;
    pq[1].pop();
  }

  printf("%lld\n", b[1]);

  return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     scanf("%d%d", &p, &c[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16748 KB Output is correct
2 Correct 12 ms 16748 KB Output is correct
3 Correct 12 ms 16748 KB Output is correct
4 Correct 12 ms 16748 KB Output is correct
5 Correct 12 ms 16748 KB Output is correct
6 Correct 12 ms 16748 KB Output is correct
7 Correct 11 ms 16748 KB Output is correct
8 Correct 12 ms 16748 KB Output is correct
9 Correct 12 ms 16748 KB Output is correct
10 Correct 12 ms 16748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16748 KB Output is correct
2 Correct 12 ms 16748 KB Output is correct
3 Correct 12 ms 16748 KB Output is correct
4 Correct 13 ms 16748 KB Output is correct
5 Correct 12 ms 16748 KB Output is correct
6 Correct 12 ms 16748 KB Output is correct
7 Correct 12 ms 16748 KB Output is correct
8 Correct 12 ms 16748 KB Output is correct
9 Correct 12 ms 16748 KB Output is correct
10 Correct 14 ms 16748 KB Output is correct
11 Correct 12 ms 16748 KB Output is correct
12 Correct 12 ms 16748 KB Output is correct
13 Correct 12 ms 16748 KB Output is correct
14 Correct 12 ms 16748 KB Output is correct
15 Correct 12 ms 16748 KB Output is correct
16 Correct 12 ms 16748 KB Output is correct
17 Correct 12 ms 16748 KB Output is correct
18 Correct 12 ms 16748 KB Output is correct
19 Correct 13 ms 16876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16748 KB Output is correct
2 Correct 12 ms 16748 KB Output is correct
3 Correct 12 ms 16748 KB Output is correct
4 Correct 12 ms 16748 KB Output is correct
5 Correct 12 ms 16748 KB Output is correct
6 Correct 12 ms 16748 KB Output is correct
7 Correct 11 ms 16748 KB Output is correct
8 Correct 12 ms 16748 KB Output is correct
9 Correct 12 ms 16748 KB Output is correct
10 Correct 12 ms 16748 KB Output is correct
11 Correct 12 ms 16748 KB Output is correct
12 Correct 12 ms 16748 KB Output is correct
13 Correct 12 ms 16748 KB Output is correct
14 Correct 13 ms 16748 KB Output is correct
15 Correct 12 ms 16748 KB Output is correct
16 Correct 12 ms 16748 KB Output is correct
17 Correct 12 ms 16748 KB Output is correct
18 Correct 12 ms 16748 KB Output is correct
19 Correct 12 ms 16748 KB Output is correct
20 Correct 14 ms 16748 KB Output is correct
21 Correct 12 ms 16748 KB Output is correct
22 Correct 12 ms 16748 KB Output is correct
23 Correct 12 ms 16748 KB Output is correct
24 Correct 12 ms 16748 KB Output is correct
25 Correct 12 ms 16748 KB Output is correct
26 Correct 12 ms 16748 KB Output is correct
27 Correct 12 ms 16748 KB Output is correct
28 Correct 12 ms 16748 KB Output is correct
29 Correct 13 ms 16876 KB Output is correct
30 Correct 12 ms 16748 KB Output is correct
31 Correct 12 ms 17004 KB Output is correct
32 Correct 13 ms 17004 KB Output is correct
33 Correct 13 ms 16984 KB Output is correct
34 Correct 15 ms 17004 KB Output is correct
35 Correct 14 ms 17132 KB Output is correct
36 Correct 14 ms 17132 KB Output is correct
37 Correct 14 ms 17132 KB Output is correct
38 Correct 15 ms 17260 KB Output is correct
39 Correct 15 ms 17260 KB Output is correct
40 Correct 14 ms 17132 KB Output is correct
41 Correct 14 ms 17132 KB Output is correct
42 Correct 14 ms 17132 KB Output is correct
43 Correct 15 ms 17132 KB Output is correct
44 Correct 14 ms 17132 KB Output is correct
45 Correct 15 ms 17132 KB Output is correct
46 Correct 15 ms 17388 KB Output is correct
47 Correct 14 ms 17388 KB Output is correct
48 Correct 14 ms 17260 KB Output is correct
49 Correct 15 ms 17388 KB Output is correct
50 Correct 15 ms 17132 KB Output is correct
51 Correct 14 ms 17132 KB Output is correct
52 Correct 14 ms 17260 KB Output is correct
53 Correct 15 ms 17260 KB Output is correct
54 Correct 15 ms 17388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16748 KB Output is correct
2 Correct 12 ms 16748 KB Output is correct
3 Correct 12 ms 16748 KB Output is correct
4 Correct 12 ms 16748 KB Output is correct
5 Correct 12 ms 16748 KB Output is correct
6 Correct 12 ms 16748 KB Output is correct
7 Correct 11 ms 16748 KB Output is correct
8 Correct 12 ms 16748 KB Output is correct
9 Correct 12 ms 16748 KB Output is correct
10 Correct 12 ms 16748 KB Output is correct
11 Correct 12 ms 16748 KB Output is correct
12 Correct 12 ms 16748 KB Output is correct
13 Correct 12 ms 16748 KB Output is correct
14 Correct 13 ms 16748 KB Output is correct
15 Correct 12 ms 16748 KB Output is correct
16 Correct 12 ms 16748 KB Output is correct
17 Correct 12 ms 16748 KB Output is correct
18 Correct 12 ms 16748 KB Output is correct
19 Correct 12 ms 16748 KB Output is correct
20 Correct 14 ms 16748 KB Output is correct
21 Correct 12 ms 16748 KB Output is correct
22 Correct 12 ms 16748 KB Output is correct
23 Correct 12 ms 16748 KB Output is correct
24 Correct 12 ms 16748 KB Output is correct
25 Correct 12 ms 16748 KB Output is correct
26 Correct 12 ms 16748 KB Output is correct
27 Correct 12 ms 16748 KB Output is correct
28 Correct 12 ms 16748 KB Output is correct
29 Correct 13 ms 16876 KB Output is correct
30 Correct 12 ms 16748 KB Output is correct
31 Correct 12 ms 17004 KB Output is correct
32 Correct 13 ms 17004 KB Output is correct
33 Correct 13 ms 16984 KB Output is correct
34 Correct 15 ms 17004 KB Output is correct
35 Correct 14 ms 17132 KB Output is correct
36 Correct 14 ms 17132 KB Output is correct
37 Correct 14 ms 17132 KB Output is correct
38 Correct 15 ms 17260 KB Output is correct
39 Correct 15 ms 17260 KB Output is correct
40 Correct 14 ms 17132 KB Output is correct
41 Correct 14 ms 17132 KB Output is correct
42 Correct 14 ms 17132 KB Output is correct
43 Correct 15 ms 17132 KB Output is correct
44 Correct 14 ms 17132 KB Output is correct
45 Correct 15 ms 17132 KB Output is correct
46 Correct 15 ms 17388 KB Output is correct
47 Correct 14 ms 17388 KB Output is correct
48 Correct 14 ms 17260 KB Output is correct
49 Correct 15 ms 17388 KB Output is correct
50 Correct 15 ms 17132 KB Output is correct
51 Correct 14 ms 17132 KB Output is correct
52 Correct 14 ms 17260 KB Output is correct
53 Correct 15 ms 17260 KB Output is correct
54 Correct 15 ms 17388 KB Output is correct
55 Correct 18 ms 17900 KB Output is correct
56 Correct 41 ms 21356 KB Output is correct
57 Correct 77 ms 24300 KB Output is correct
58 Correct 83 ms 26472 KB Output is correct
59 Correct 110 ms 29800 KB Output is correct
60 Correct 136 ms 32616 KB Output is correct
61 Correct 187 ms 35428 KB Output is correct
62 Correct 184 ms 37088 KB Output is correct
63 Correct 219 ms 40920 KB Output is correct
64 Correct 230 ms 41956 KB Output is correct
65 Correct 115 ms 36972 KB Output is correct
66 Correct 120 ms 36844 KB Output is correct
67 Correct 115 ms 37100 KB Output is correct
68 Correct 170 ms 38752 KB Output is correct
69 Correct 228 ms 39024 KB Output is correct
70 Correct 231 ms 38760 KB Output is correct
71 Correct 205 ms 51872 KB Output is correct
72 Correct 201 ms 51804 KB Output is correct
73 Correct 177 ms 47836 KB Output is correct
74 Correct 177 ms 48092 KB Output is correct
75 Correct 181 ms 46944 KB Output is correct
76 Correct 181 ms 47164 KB Output is correct
77 Correct 191 ms 46328 KB Output is correct
78 Correct 187 ms 45668 KB Output is correct
79 Correct 174 ms 45016 KB Output is correct