Submission #110103

#TimeUsernameProblemLanguageResultExecution timeMemory
110103nxteruFireworks (APIO16_fireworks)C++14
7 / 100
10 ms7424 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,x[300005],y[300005],s[300005]; vector<P>g[300005]; void dfs(int v){ if(g[v].size()==0)return; vector<ll>r; for(int i=0;i<g[v].size();i++){ ll u=g[v][i].F,c=g[v][i].S; dfs(u); x[u]+=c; y[u]+=c; r.PB(x[u]); r.PB(y[u]); } sort(r.begin(),r.end()); x[v]=r[g[v].size()-1]; y[v]=r[g[v].size()]; for(int i=0;i<g[v].size();i++){ ll u=g[v][i].F; s[v]+=s[u]; if(x[v]<x[u])s[v]+=x[u]-x[v]; if(x[v]>y[u])s[v]+=x[v]-y[u]; } } int main(void){ scanf("%lld%lld",&n,&m); n+=m; for(int i=1;i<n;i++){ ll p,c; scanf("%lld%lld",&p,&c); g[--p].PB(P(i,c)); } dfs(0); printf("%lld\n",s[0]); }

Compilation message (stderr)

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:13:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[v].size();i++){
              ~^~~~~~~~~~~~
fireworks.cpp:24: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:32: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:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld",&p,&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...