이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
#define x first
#define y second
const int maxn = 300004;
int N1, N2, N;
vector<pint> g[maxn];
struct func {
priority_queue<int> neg;
priority_queue<int, vector<int>, greater<int> > pos;
lint mn = 0;
void add(int x, int y, int z) {
neg.push(x);
pos.push(y);
mn += z;
while (neg.top() > pos.top()) {
int x = neg.top(), y = pos.top();
neg.pop(); pos.pop();
pos.push(x); neg.push(y);
mn += x - y;
}
}
};
func dfs(int x) {
func f;
for (pint i : g[x]) {
int k = i.x, t = i.y;
func g = dfs(k);
if (k <= N1) f.add(g.neg.top() + t, g.pos.top() + t, g.mn);
else f.add(t, t, 0);
}
return f;
}
main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> N1 >> N2;
N = N1 + N2;
for (int i=2; i<=N; i++) {
int x, y;
cin >> x >> y;
g[x].emplace_back(i, y);
}
dfs(1);
cout << dfs(1).mn << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
fireworks.cpp:44:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^| # | 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... |