# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
386039 | MiricaMatei | Fireworks (APIO16_fireworks) | C++14 | 14 ms | 16876 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
vector<int>G[MAXN];
priority_queue<int>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) {
int x = pq[i].top();
a[i]--;
b[i] += x;
pq[i].pop();
}
b[i] -= c[i];
int x1 = pq[i].top();
pq[i].pop();
int 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) {
int x = pq[1].top();
a[1]--;
b[1] += x;
pq[1].pop();
}
printf("%lld\n", b[1]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |