# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
329218 | 2020-11-19T22:50:16 Z | Nirjhor | Fireworks (APIO16_fireworks) | C++17 | 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
# | 결과 | 실행 시간 | 메모리 | 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 | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 7404 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | 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 | - |
# | 결과 | 실행 시간 | 메모리 | 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 | - |