Submission #405099

#TimeUsernameProblemLanguageResultExecution timeMemory
405099PyqeArboras (RMI20_arboras)C++11
0 / 100
5053 ms10760 KiB
#include <bits/stdc++.h> using namespace std; long long n,a[100069],dh[100069],fh[100069],z; vector<long long> al[100069]; void bd(long long x) { long long i,sz=al[x].size(),l,mx[2]={dh[x],dh[x]}; fh[x]=dh[x]; for(i=0;i<sz;i++) { l=al[x][i]; dh[l]=dh[x]+a[l]; bd(l); fh[x]=max(fh[x],fh[l]); mx[1]=max(mx[1],min(mx[0],fh[l])); mx[0]=max(mx[0],fh[l]); } z+=mx[0]+mx[1]-dh[x]*2; } int main() { long long t,rr,i,k,l; scanf("%lld",&n); for(i=2;i<=n;i++) { scanf("%lld",&k); k++; al[k].push_back(i); } for(i=2;i<=n;i++) { scanf("%lld",a+i); } scanf("%lld",&t); for(rr=0;rr<=t;rr++) { if(rr) { scanf("%lld%lld",&k,&l); k++; a[k]+=l; } z=0; bd(1); printf("%lld\n",z); } }

Compilation message (stderr)

arboras.cpp: In function 'int main()':
arboras.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  scanf("%lld",&n);
      |  ~~~~~^~~~~~~~~~~
arboras.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   scanf("%lld",&k);
      |   ~~~~~^~~~~~~~~~~
arboras.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%lld",a+i);
      |   ~~~~~^~~~~~~~~~~~
arboras.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%lld",&t);
      |  ~~~~~^~~~~~~~~~~
arboras.cpp:45:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |    scanf("%lld%lld",&k,&l);
      |    ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...