| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 953168 | Unforgettablepl | Fireworks (APIO16_fireworks) | C++17 | 459 ms | 129816 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <utility>
using namespace std;
#define int long long
struct line{
int m,n;
multiset<int> points;
line():n(0),m(0),points(){}
line(int m,int n,multiset<int> points):m(m),n(n),points(points){}
void operator+=(const line &other){
m+=other.m;
n+=other.n;
for(int i:other.points)points.insert(i);
}
};
int n,m;
vector<pair<int,int>> adj[300001];
line functions[300001];
void dfs(int x,int p){
if(x>n) {
functions[x] = {1, -adj[x][0].second, {adj[x][0].second, adj[x][0].second}};
return;
}
int len = 0;
for(auto&i:adj[x]){
if(i.first!=p){
dfs(i.first,x);
if(functions[i.first].points.size()>functions[x].points.size())swap(functions[x],functions[i.first]);
functions[x]+=functions[i.first];
}
else len = i.second;
}
int currsum = functions[x].n;
int currslope = functions[x].m;
for(auto i=--functions[x].points.end();i!=functions[x].points.begin();i--){
currslope--;
if(currslope==-1)break;
currsum+=*i;
}
while(functions[x].m>1){
functions[x].m--;
functions[x].points.erase(--functions[x].points.end());
}
int f = *--functions[x].points.end();
functions[x].points.erase(--functions[x].points.end());
int s = *--functions[x].points.end();
functions[x].points.erase(--functions[x].points.end());
functions[x].points.insert(s+len);
functions[x].points.insert(f+len);
functions[x].n = currsum-(f+len);
functions[x] = functions[x];
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for(int i=2;i<=n+m;i++){
int p,c;cin>>p>>c;
adj[i].emplace_back(p,c);
adj[p].emplace_back(i,c);
}
dfs(1,0);
line ans = functions[1];
int currsum = ans.n;
int currslope = ans.m;
for(auto i=--ans.points.end();i!=ans.points.begin();i--){
currslope--;
if(currslope==-1)break;
currsum+=*i;
}
cout << currsum << '\n';
}컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
