# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
955778 | sleepntsheep | Fireworks (APIO16_fireworks) | C++17 | 152 ms | 70988 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define N 300001
int n,M;
int e[N][3],eo,h[N];
std::priority_queue<long long> pq[N];
long long m[N],c[N];
void link(int u,int v,int w) { e[++eo][0]=v,e[eo][1]=w,e[eo][2]=h[u],h[u]=eo; }
void dfs(int u,int p,int ci)
{
m[u]=c[u]=0;
if(u > n)
{
pq[u].push(ci);
pq[u].push(ci);
m[u]=1;
c[u]=-ci;
return;
}
for(int v,j=h[u];j;j=e[j][2])if((v=e[j][0])-p)
{
dfs(v,u,e[j][1]);
if(pq[v].size()>pq[u].size()) { std::swap(pq[v],pq[u]); std::swap(m[u],m[v]), std::swap(c[u],c[v]); }
while(pq[v].size()) pq[u].push(pq[v].top()), pq[v].pop();
m[u]+=m[v];
c[u]+=c[v];
}
if(u!=1)
{
while(m[u]>1)
{
--m[u];
c[u]+=pq[u].top();
pq[u].pop();
}
long long x=pq[u].top();
pq[u].pop();
long long x2=pq[u].top();
pq[u].pop();
pq[u].push(x+ci);
pq[u].push(x2+ci);
c[u]-=ci;
}
else
{
while(m[1]>0)
{
--m[1];
c[1]+=pq[1].top();
pq[1].pop();
}
printf("%lld",c[1]);
}
}
int main()
{
scanf("%d%d",&n,&M);
for(int p,c,i=2;i<=n+M;++i) scanf("%d%d",&p,&c),link(p,i,c);
dfs(1,1,-1);
}
컴파일 시 표준 에러 (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... |