Submission #329218

# Submission time Handle Problem Language Result Execution time Memory
329218 2020-11-19T22:50:16 Z Nirjhor Fireworks (APIO16_fireworks) C++17
0 / 100
7 ms 7404 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 300010;

int n, m, p[N];
vector <int> g[N];
ll w[N], a[N], b[N];
priority_queue <ll> *pq[N];

int main() {
  cin >> m >> n; n += m;
  for (int i = 2; i <= n; ++i) {
    scanf("%d %lld", p + i, w + i);
    g[p[i]].emplace_back(i);
  }
  for (int i = m + 1; i <= n; ++i) {
    a[i] = 1, b[i] = -w[i];
    pq[i] = new priority_queue <ll> ();
    pq[i] -> emplace(w[i]); pq[i] -> emplace(w[i]);
  }
  for (int i = m; i >= 2; --i) {
    pq[i] = new priority_queue <ll> ();
    for (int j : g[i]) {
      if (pq[j] -> size() > pq[i] -> size()) swap(pq[i], pq[j]);
      while (!(pq[j] -> empty())) pq[i] -> emplace(pq[j] -> top()), pq[j] -> pop();
      a[i] += a[j], b[i] += b[j];
    }
    while (a[i] > 1) b[i] += pq[i] -> top(), --a[i], pq[i] -> pop(); b[i] -= w[i];
    ll one = pq[i] -> top(); pq[i] -> pop();
    ll two = pq[i] -> top(); pq[i] -> pop();
    pq[i] -> emplace(one + w[i]); pq[i] -> emplace(two + w[i]);
  }
  cout << a[2] * pq[2] -> top() + b[2] << '\n';
  return 0;
}


Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:32:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   32 |     while (a[i] > 1) b[i] += pq[i] -> top(), --a[i], pq[i] -> pop(); b[i] -= w[i];
      |     ^~~~~
fireworks.cpp:32:70: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   32 |     while (a[i] > 1) b[i] += pq[i] -> top(), --a[i], pq[i] -> pop(); b[i] -= w[i];
      |                                                                      ^
fireworks.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |     scanf("%d %lld", p + i, w + i);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7404 KB Output is correct
2 Incorrect 5 ms 7404 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 7404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7404 KB Output is correct
2 Incorrect 5 ms 7404 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7404 KB Output is correct
2 Incorrect 5 ms 7404 KB Output isn't correct
3 Halted 0 ms 0 KB -