Submission #405101

# Submission time Handle Problem Language Result Execution time Memory
405101 2021-05-15T17:26:23 Z Pyqe Arboras (RMI20_arboras) C++11
11 / 100
5000 ms 8672 KB
#include <bits/stdc++.h>

using namespace std;

const long long dv=1e9+7;
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=(z+mx[0]+mx[1]-dh[x]*2)%dv;
}

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

arboras.cpp: In function 'int main()':
arboras.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%lld",&n);
      |  ~~~~~^~~~~~~~~~~
arboras.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%lld",&k);
      |   ~~~~~^~~~~~~~~~~
arboras.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   scanf("%lld",a+i);
      |   ~~~~~^~~~~~~~~~~~
arboras.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  scanf("%lld",&t);
      |  ~~~~~^~~~~~~~~~~
arboras.cpp:46:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |    scanf("%lld%lld",&k,&l);
      |    ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2636 KB Output is correct
2 Correct 16 ms 2768 KB Output is correct
3 Correct 17 ms 2732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5054 ms 6844 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5065 ms 8672 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2636 KB Output is correct
2 Correct 16 ms 2768 KB Output is correct
3 Correct 17 ms 2732 KB Output is correct
4 Execution timed out 5054 ms 6844 KB Time limit exceeded
5 Halted 0 ms 0 KB -