| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1020314 | vjudge1 | Fireworks (APIO16_fireworks) | C++14 | 224 ms | 21612 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>//I love Kagamine Rin forever!
#define ll long long
using namespace std;//() is so cute!
struct lmt
{
ll v[600005];
int lc[600005],rc[600005],dist[600005];
lmt(){dist[0]=-1;}
int merge(int x,int y)
{
if(!x||!y)return x+y;
if(v[y]>v[x])swap(x,y);
rc[x]=merge(rc[x],y);
if(dist[lc[x]]<dist[rc[x]])swap(lc[x],rc[x]);
dist[x]=dist[rc[x]]+1;
return x;
}
int pop(int x)
{
return merge(lc[x],rc[x]);
}
}akari;
int sz;
int rt[600005];
int n,m;
int fa[600005],c[600005];
int deg[600005];
ll ans;
int main()
{
scanf("%d%d",&n,&m);
for(int i=2;i<=n+m;i++)
{
scanf("%d%d",&fa[i],&c[i]);
deg[fa[i]]++;
ans+=c[i];
}
for(int i=n+m;i>=2;i--)
{
ll l=0,r=0;
if(i<=n)
{
while(--deg[i])rt[i]=akari.pop(rt[i]);
r=akari.v[rt[i]],rt[i]=akari.pop(rt[i]);
l=akari.v[rt[i]],rt[i]=akari.pop(rt[i]);
}
akari.v[++sz]=l+c[i],akari.v[++sz]=r+c[i];
rt[i]=akari.merge(rt[i],akari.merge(sz,sz-1));
rt[fa[i]]=akari.merge(rt[fa[i]],rt[i]);
}
while(deg[1]--)rt[1]=akari.pop(rt[1]);
while(rt[1])ans-=akari.v[rt[1]],rt[1]=akari.pop(rt[1]);
printf("%lld\n",ans);
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... | ||||
