QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#284189 | #5683. 大富翁 | simonG# | WA | 69ms | 20840kb | C++14 | 752b | 2023-12-16 11:56:26 | 2023-12-16 11:56:26 |
Judging History
answer
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int N=4e5+10;
int n,a[N],fa[N];
int siz[N],dep[N],val[N];
int ans=0;
vector<int> e[N];
void dfs(int u,int f) {
dep[u]=dep[f]+1; siz[u]=1;
for(int v:e[u]) {
dfs(v,u);
siz[u]+=siz[v];
}
}
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]),e[fa[i]].push_back(i);
dfs(1,1);
for(int i=1; i<=n; i++) val[i]=siz[i]-dep[i]-a[i];
priority_queue<int> q;
for(int i=1; i<=n; i++) q.push(val[i]);
for(; q.size(); ) {
int x=q.top(); q.pop();
ans+=x;
if(q.size()) q.pop();
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 13080kb
input:
8 0 1 1 0 0 0 0 0 3 1 8 4 1 3 1
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 13072kb
input:
10 1 0 0 0 0 0 0 0 0 1 8 1 9 10 9 8 4 5 1
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 0ms
memory: 13124kb
input:
8 1 0 1 0 0 1 0 0 1 6 2 1 2 1 5
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 0ms
memory: 13176kb
input:
8 0 0 0 1 1 0 1 1 7 1 3 4 1 4 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 5ms
memory: 13080kb
input:
10 0 0 1 0 0 0 0 1 1 0 1 5 1 1 9 1 2 4 4
output:
3
result:
ok single line: '3'
Test #6:
score: 0
Accepted
time: 55ms
memory: 20756kb
input:
199998 2 2 3 2 1 3 0 2 0 3 2 0 2 2 1 1 3 3 3 3 2 0 1 2 0 3 1 1 0 0 3 3 3 3 0 3 2 2 1 1 2 2 0 3 3 3 1 2 0 2 2 1 2 0 3 2 0 0 0 3 2 3 0 1 1 2 0 2 2 0 3 1 1 2 3 1 0 3 0 2 1 0 3 3 1 1 2 3 1 0 3 0 1 2 3 1 3 3 0 3 1 2 1 1 3 2 1 3 3 3 1 1 2 3 2 0 2 3 2 2 1 1 2 1 2 0 1 0 1 3 3 2 3 2 0 3 2 2 2 0 3 2 1 2 3 1 2...
output:
-101057
result:
ok single line: '-101057'
Test #7:
score: 0
Accepted
time: 69ms
memory: 20840kb
input:
199992 2 2 0 0 2 0 1 2 1 2 2 1 1 2 1 1 3 0 0 3 1 0 2 0 0 1 0 3 2 0 2 3 2 3 2 0 3 2 2 2 3 2 1 3 1 1 2 3 1 2 0 0 2 2 0 3 1 1 0 1 1 1 0 2 3 0 3 0 3 1 3 2 3 1 0 3 2 2 3 1 3 0 2 2 0 3 2 2 1 1 0 1 2 0 1 3 1 2 1 1 3 3 1 2 1 3 0 1 1 1 2 1 2 0 2 0 0 0 2 0 0 3 1 3 0 1 1 0 3 1 1 2 3 1 1 0 2 0 3 2 1 2 0 2 1 0 0...
output:
-63508
result:
ok single line: '-63508'
Test #8:
score: 0
Accepted
time: 67ms
memory: 20720kb
input:
199993 2 3 0 1 3 3 2 1 0 2 2 0 3 1 2 2 1 2 2 3 0 1 0 0 2 1 1 3 2 1 0 2 1 2 2 3 3 3 1 2 2 2 1 3 2 2 0 2 3 3 2 1 3 0 1 3 3 2 1 1 3 0 2 2 0 3 1 3 2 0 1 1 3 0 0 2 3 2 1 0 1 1 3 0 1 0 2 3 2 1 0 3 2 2 3 1 3 2 2 0 1 2 2 0 2 1 2 0 1 1 1 2 2 3 2 1 2 2 0 0 2 3 3 1 1 0 3 2 2 3 1 3 2 1 3 0 2 3 0 3 0 3 3 2 1 2 2...
output:
-72819
result:
ok single line: '-72819'
Test #9:
score: 0
Accepted
time: 52ms
memory: 20740kb
input:
200000 0 2 2 2 2 3 2 1 2 3 3 1 2 1 0 1 2 1 2 3 1 2 2 3 3 3 2 2 0 3 3 0 0 1 3 3 0 1 0 1 0 0 2 0 1 3 1 0 1 2 1 1 1 2 1 3 3 3 2 2 1 2 0 2 1 0 3 2 1 0 0 3 1 3 1 0 2 0 1 3 2 1 3 3 2 3 3 1 3 2 2 0 0 1 2 0 3 3 1 0 3 2 1 3 1 3 0 0 2 3 1 2 3 0 0 0 2 3 1 0 1 1 3 2 2 6 3 2 2 0 2 1 0 2 3 0 0 0 1 2 3 1 1 1 2 2 3...
output:
-87803
result:
ok single line: '-87803'
Test #10:
score: -100
Wrong Answer
time: 68ms
memory: 20764kb
input:
199994 69536 93956 146435 58370 55904 55731 40099 34869 22948 62455 25557 61814 118354 34694 37607 102825 86029 141405 6587 18273 174985 101354 139220 168750 14953 92256 162412 164115 172096 52676 126381 152299 140824 180431 131743 128463 115582 173595 160676 168294 26378 66194 115896 193154 79199 4...
output:
-1410276652
result:
wrong answer 1st lines differ - expected: '-10000211244', found: '-1410276652'