이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,fa[600005],w[600005],rd[600005];
int rt[600005],lc[600005],rc[600005],v[600005],dis[600005],tot,ans;
int getnew(int x){
v[++tot]=x;return tot;
}
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(dis[lc[x]]<dis[rc[x]])swap(lc[x],rc[x]);
dis[x]=dis[rc[x]]+1;
return x;
}
signed main(){
scanf("%lld%lld",&n,&m);dis[0]=-1;
for(int i=2;i<=n+m;i++){
scanf("%lld%lld",&fa[i],&w[i]);rd[fa[i]]++;
ans+=w[i];
}
for(int i=n+m;i>=2;i--){
int l=0,r=0;
if(i<=n)while(rd[i]-->1)rt[i]=merge(lc[rt[i]],rc[rt[i]]);
r=v[rt[i]],rt[i]=merge(lc[rt[i]],rc[rt[i]]);
l=v[rt[i]],rt[i]=merge(lc[rt[i]],rc[rt[i]]);
rt[i]=merge(rt[i],merge(getnew(l+w[i]),getnew(r+w[i])));
rt[fa[i]]=merge(rt[fa[i]],rt[i]);
}
while(rd[1]--)rt[1]=merge(lc[rt[1]],rc[rt[1]]);
while(rt[1])ans=ans-v[rt[1]],rt[1]=merge(lc[rt[1]],rc[rt[1]]);
printf("%lld",ans);
}
컴파일 시 표준 에러 (stderr) 메시지
fireworks.cpp: In function 'int main()':
fireworks.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%lld%lld",&n,&m);dis[0]=-1;
| ~~~~~^~~~~~~~~~~~~~~~~~
fireworks.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | scanf("%lld%lld",&fa[i],&w[i]);rd[fa[i]]++;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |