QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#87081#4406. 独立集问题Bird0 105ms75160kbC++141.0kb2023-03-11 16:53:472023-03-11 16:53:50

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-11 16:53:50]
  • 评测
  • 测评结果:0
  • 用时:105ms
  • 内存:75160kb
  • [2023-03-11 16:53:47]
  • 提交

answer

#include<bits/stdc++.h>
#define N 351493
using namespace std;
int n,d[N+5],fa[N+5];
long long f[N+5][3][2]; //x±»Ë­³ÔÁË£»faÊÇ·ñ±»x³ÔÁË 
vector<int> e[N+5];
inline void dfs(int x)
{
	static long long w[3][2];
	for(int y:e[x]) dfs(y);
	auto getw=[&](bool type)
	{
		memset(w,0,32),w[1][0]=(type?-d[x]:d[x]),w[2][0]=-1e18;
		for(int y:e[x])
		{
			int temp=max({f[y][0][0]+(type?d[y]:-d[y]),f[y][1][0],f[y][2][0]});
			w[0][0]+=temp,w[1][0]+=max({f[y][0][0]+(type?d[y]:-d[y]),f[y][2][0]});
			w[2][0]+=max(w[2][0]+temp,w[2][1]+max(f[y][1][1],f[y][2][1])),w[2][1]+=temp;
		}
		w[1][1]=w[1][0]+(type?d[fa[x]]:-d[fa[x]]),w[2][1]=w[2][0]+(type?d[fa[x]]:-d[fa[x]]);
	};
	getw(1),memcpy(f[x],w,32),getw(0);
	for(int i=0;i<3;++i) for(int j=0;j<2;++j) f[x][i][j]=max(f[x][i][j],w[i][j]);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",d+i);
	for(int i=2;i<=n;++i) scanf("%d",fa+i),e[fa[i]].push_back(i);
	dfs(1),printf("%lld\n",max(f[1][1][0],f[1][2][0]));
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 81ms
memory: 75160kb

input:

351493
-641495974 -401868912 -864400429 35718599 -579296290 767835327 149511992 -246228754 649472235 893048442 -292675192 -788090312 -578172296 -62289673 196890164 -120059197 -452848333 -216788131 -604555771 -240241020 376984486 -407661514 -107574590 -461679558 -470560314 -583391402 -991686079 76956...

output:

1719042380

result:

wrong answer 1st numbers differ - expected: '175477002777567', found: '1719042380'

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 105ms
memory: 39504kb

input:

351493
915594742 688454502 456077914 208864399 625937959 102483811 538999077 529481828 400375958 387560315 83710527 83424975 330114353 684812426 68052931 28849220 295907801 535129167 967891325 124069427 644256858 757666812 558755455 178666038 177054898 795236216 848264282 669310447 328353372 3681163...

output:

5982388106

result:

wrong answer 1st numbers differ - expected: '175766699890054', found: '5982388106'

Subtask #3:

score: 0
Wrong Answer

Test #41:

score: 0
Wrong Answer
time: 1ms
memory: 11800kb

input:

7
247522519 398923496 -976223527 806215585 -937536479 -130552271 90576461
1 2 1 2 5 5

output:

3092505300

result:

wrong answer 1st numbers differ - expected: '3587550338', found: '3092505300'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%