제출 #349291

#제출 시각아이디문제언어결과실행 시간메모리
349291denkendoemeerFireworks (APIO16_fireworks)C++14
100 / 100
293 ms63892 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; priority_queue<ll>pq[300005]; vector<ll>g[300005]; ll sz[300005],cost[300005]; void merg(ll x,ll y) { if (pq[x].size()<pq[y].size()) swap(pq[x],pq[y]); while(!pq[y].empty()){ pq[x].push(pq[y].top()); pq[y].pop(); } sz[x]+=sz[y]; } void dfs(ll nod) { ll x,y,sum=0; sz[nod]=cost[nod]; for(auto &it:g[nod]){ dfs(it); sum++; merg(nod,it); } if (sum==0){ pq[nod].push(cost[nod]); pq[nod].push(cost[nod]); } else{ while(sum>1) pq[nod].pop(),sum--; x=pq[nod].top(); pq[nod].pop(); y=pq[nod].top(); pq[nod].pop(); pq[nod].push(x+cost[nod]); pq[nod].push(y+cost[nod]); } } int main() { //freopen(".in","r",stdin); //freopen(".out","w",stdout); ll n,m,x,i; scanf("%lld%lld",&n,&m); for(i=2;i<=n+m;i++){ scanf("%lld%lld",&x,&cost[i]); g[x].push_back(i); } dfs(1); x=pq[1].top(); pq[1].pop(); pq[1].push(0); ll num=0,ans=0; while(!pq[1].empty()){ ans=ans+num*(x-pq[1].top()); x=pq[1].top(); pq[1].pop(); num--; } printf("%lld\n",sz[1]+ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

fireworks.cpp: In function 'int main()':
fireworks.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
fireworks.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |         scanf("%lld%lld",&x,&cost[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...