Submission #111515

#TimeUsernameProblemLanguageResultExecution timeMemory
111515nxteruFireworks (APIO16_fireworks)C++14
0 / 100
18 ms16768 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; #define F first #define S second #define PB push_back ll n,m,ans,vs[300005]; priority_queue<ll>p[300005]; vector<P>g[300005]; void up(int v,ll c){ if(p[v].size()==0){ p[v].push(c); p[v].push(c); }else{ ll x=p[v].top(); p[v].pop(); ll y=p[v].top(); p[v].pop(); p[v].push(x+c); p[v].push(y+c); } } void merge(int x,int y){ if(p[vs[x]].size()<p[vs[y]].size())swap(x,y); int py=y; y=vs[y]; x=vs[x]; vs[py]=x; if(p[y].size()==0)return; ll mi=min(p[x].top(),p[y].top()); while(!p[y].empty()){ p[x].push(p[y].top()); p[y].pop(); } p[x].pop(); ans+=p[x].top()-mi; } void dfs(int v){ if(g[v].size()==0)return; for(int i=0;i<g[v].size();i++){ ll u=g[v][i].F,c=g[v][i].S; dfs(u); up(vs[u],c); merge(v,u); } } int main(void){ scanf("%lld%lld",&n,&m); n+=m; for(int i=0;i<n;i++)vs[i]=i; for(int i=1;i<n;i++){ ll q,c; scanf("%lld%lld",&q,&c); g[--q].PB(P(i,c)); } dfs(0); printf("%lld\n",ans); }

Compilation message (stderr)

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:41:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[v].size();i++){
              ~^~~~~~~~~~~~
fireworks.cpp: In function 'int main()':
fireworks.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~~~~
fireworks.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld",&q,&c);
   ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...