답안 #405099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405099 2021-05-15T17:23:22 Z Pyqe Arboras (RMI20_arboras) C++11
0 / 100
5000 ms 10760 KB
#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

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);
      |    ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 2728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5053 ms 8000 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5016 ms 10760 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 2728 KB Output isn't correct
2 Halted 0 ms 0 KB -