Submission #42616

#TimeUsernameProblemLanguageResultExecution timeMemory
42616repeatingFireworks (APIO16_fireworks)C++11
7 / 100
7 ms7788 KiB
#include <bits/stdc++.h> #define F first #define S second #define P push #define pb push_back #define MEM(dp,i) memset(dp,i,sizeof(dp)) #define W while #define R return #define C continue #define SI size() #define ll long long #define ld long double #define pll pair<ll,ll> #define pii pair<int,int> #define SF(x) scanf("%Id",&x) #define SF2(x,y) scanf("%Id%Id",&x,&y) #define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z) #define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o) #define all(v) v.begin(),v.end() using namespace std; const long long INF = 1e9+1; const long long MOD = 1e9+7; const int MX=300015; int l[MX],r[MX]; vector<pii> adj[MX]; int cur=0; int val[MX]; int a[MX]; int n,m; void dfs(int ver,int val){ l[ver]=cur; int ret=0; for(auto i : adj[ver]){ dfs(i.F,val+i.S); } if(ver>n)a[ver]=val,cur++; r[ver]=cur-1; } ll res; pii seg(vector<pii> &v){ sort(all(v)); ll sum=0,l=0,r=0; ll mn=INF*INF; int rl=INF,rr=0; for(auto i : v){ if(i.S==1) sum+=i.F-v[0].F,r++; } r--; mn=sum; rl=v[0].F,rr=v[0].F; for(int i=1;i<v.size();i++){ sum-=1LL*r*(v[i].F-v[i-1].F); sum+=1LL*l*(v[i].F-v[i-1].F); if(v[i].S==1)r--; else l++; if(mn==sum){ mn=sum; rl=min(rl,v[i].F); rr=max(rr,v[i].F); } if(mn>sum){ mn=sum; rr=v[i].F; rl=v[i].F; } } res+=mn; R{rl,rr}; } pii pro(int ver){ if(ver>n){ R {a[ver],a[ver]}; } pii ret; vector<pii> v; pii p; for(auto i : adj[ver]){ p=pro(i.F); v.pb({p.F,1}); v.pb({p.S,2}); } ret=seg(v); // cout<<ver<<" "<<res<<endl; R ret; } int main(){ cin>>n>>m; for(int i=2;i<=n+m;i++){ int x,y; scanf("%d%d",&x,&y); adj[x].pb({i,y}); } dfs(1,0); pro(1); cout<<res; }

Compilation message (stderr)

fireworks.cpp: In function 'void dfs(int, int)':
fireworks.cpp:34:9: warning: unused variable 'ret' [-Wunused-variable]
     int ret=0;
         ^
fireworks.cpp: In function 'std::pair<int, int> seg(std::vector<std::pair<int, int> >&)':
fireworks.cpp:54:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<v.size();i++){
                  ^
fireworks.cpp: In function 'int main()':
fireworks.cpp:93:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&x,&y);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...