QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#86978 | #4406. 独立集问题 | xxzx | 0 | 100ms | 77808kb | C++14 | 766b | 2023-03-11 15:40:16 | 2023-03-11 15:40:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=4e5+10;
int n,a[N],fa[N];
vector<int> g[N];
ll f[N][2][2];
void dfs(int x) {
f[x][1][0]=-a[x], f[x][1][1]=-a[x]+a[fa[x]];
ll s=0;
for(auto y:g[x]) {
dfs(y);
f[x][0][0]+=f[y][1][0];
f[x][1][0]+=max(f[y][0][0]+a[y],f[y][1][0]);
f[x][1][1]+=max(f[y][0][0]+a[y],f[y][1][0]);
s+=f[y][1][0];
}
for(auto y:g[x]) f[x][1][0]=max(f[x][1][0],s-f[y][1][0]+f[y][1][1]);
f[x][0][0]=abs(f[x][0][0]), f[x][1][0]=abs(f[x][1][0]), f[x][1][1]=abs(f[x][1][1]);
return;
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=2;i<=n;i++) scanf("%d",&fa[i]), g[fa[i]].emplace_back(i);
dfs(1);
printf("%lld\n",f[1][1][0]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 100ms
memory: 77808kb
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:
160586543808083
result:
wrong answer 1st numbers differ - expected: '175477002777567', found: '160586543808083'
Subtask #2:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 93ms
memory: 36908kb
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:
123919882124292
result:
wrong answer 1st numbers differ - expected: '175766699890054', found: '123919882124292'
Subtask #3:
score: 0
Wrong Answer
Test #41:
score: 0
Wrong Answer
time: 6ms
memory: 16052kb
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%