# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
139933 | nvmdava | Fireworks (APIO16_fireworks) | C++17 | 457 ms | 93604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int p[300005];
int b[300005];
ll a[300005];
priority_queue<pair<long long, int> > pq[300005];
vector<int> ch[300005];
void dfs(int v){
int big = 0;
for(int& x : ch[v]){
dfs(x);
if(pq[big].size() < pq[x].size()) big = x;
}
if(big == 0){
pq[v].push({0, -1});
pq[v].push({a[v], 1});
pq[v].push({a[v], 1});
return;
}
swap(pq[big], pq[v]);
int g = ch[v].size();
for(auto& x : ch[v]){
if(x == big) continue;
while(!pq[x].empty()){
pq[v].push(pq[x].top());
pq[x].pop();
}
}
ll t, t2;
while(g > -1){
t2 = t;
t = pq[v].top().first;
g -= pq[v].top().second;
pq[v].pop();
}
pq[v].push({t + a[v], 1});
pq[v].push({t + a[v] + t2 - t, 1});
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin>>n>>m;
ll y = 0;
for(int i = 2; i <= n + m; i++){
cin>>p[i]>>a[i];
y += a[i];
ch[p[i]].push_back(i);
}
dfs(1);
ll t = pq[1].top().first;
while(!pq[1].empty()){
y += (t - pq[1].top().first) * pq[1].top().second;
pq[1].pop();
}
cout<<y;
}
컴파일 시 표준 에러 (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... |