ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214159 | #2045. c | laiyishi | 20 | 725ms | 29152kb | C++11 | 673b | 2024-11-15 20:59:13 | 2024-11-15 23:26:33 |
answer
#include<bits/stdc++.h>
using namespace std;
int n,w[500005],d[500005];
vector<int>g[500005];
vector<int>ans;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
int a;scanf("%d",&a);
if(a==0)continue;
g[a].push_back(i);d[i]++;
}
for(int i=1;i<=n;i++)scanf("%d",&w[i]);
priority_queue<pair<int,int>>q;
for(int i=1;i<=n;i++)if(!d[i])q.push(make_pair(-w[i],i));
while(!q.empty()){
int x=q.top().second;q.pop();
ans.push_back(x);
for(int y:g[x]){
if(--d[y]==0)q.push(make_pair(-w[y],y));
}
}
if(ans.size()==n){
long long ret=0;
for(int i=0;i<n;i++)ret+=1ll*w[ans[i]]*(i+1);
printf("%d\n",ret);
}else printf("-1\n");
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 12956kb
input:
10 2 8 3 4 1 2 4 8 5 8 1 2 8 1 10 2 9 8 8 8
output:
-1
result:
ok "-1"
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 12972kb
input:
10 0 9 5 5 0 0 0 0 0 0 576848570 9374579 447058478 375476508 17899037 890199416 691424702 96833317 4...
output:
1893569698
result:
wrong answer 1st words differ - expected: '27663373474', found: '1893569698'
Test #3:
score: 10
Accepted
time: 0ms
memory: 12972kb
input:
15 0 0 0 12 6 0 0 14 8 0 0 7 6 15 0 1 4 7 1 5 1 1 6 8 6 1 1 2 6 2
output:
571
result:
ok "571"
Test #4:
score: 0
Wrong Answer
time: 4ms
memory: 12972kb
input:
15 10 0 13 14 0 0 4 9 0 2 0 0 0 0 10 699156165 159021634 857055962 44497989 345951671 893758337 8465...
output:
753203202
result:
wrong answer 1st words differ - expected: '78062614530', found: '753203202'
Test #5:
score: 0
Wrong Answer
time: 4ms
memory: 13000kb
input:
1000 144 384 112 973 710 47 773 579 421 233 4 657 112 596 133 780 803 571 300 804 34 291 507 270 79 ...
output:
33001045
result:
wrong answer 1st words differ - expected: '37419575', found: '33001045'
Test #6:
score: 0
Wrong Answer
time: 4ms
memory: 13004kb
input:
1000 349 415 281 956 749 201 628 217 723 900 513 106 618 978 176 448 834 704 763 266 466 533 192 379...
output:
757866342
result:
wrong answer 1st words differ - expected: '370124146702558', found: '757866342'
Test #7:
score: 0
Wrong Answer
time: 38ms
memory: 16164kb
input:
100000 14420 84013 87193 82068 10374 79474 25939 9590 32198 3548 47938 85741 12568 14530 8858 60495 ...
output:
-744048675
result:
wrong answer 1st words differ - expected: '37283654934273540', found: '-744048675'
Test #8:
score: 0
Wrong Answer
time: 39ms
memory: 16172kb
input:
100000 26403 63914 61602 32321 29105 19251 73439 61190 72905 30337 25317 66634 83841 38470 96206 848...
output:
2145510419
result:
wrong answer 1st words differ - expected: '140620474524379753', found: '2145510419'
Test #9:
score: 0
Wrong Answer
time: 316ms
memory: 29152kb
input:
500000 331714 145478 6577 175958 171774 304559 166867 26414 92325 132061 8297 12915 470473 419957 48...
output:
-1604234695
result:
wrong answer 1st words differ - expected: '4728510666048798028', found: '-1604234695'
Test #10:
score: 0
Wrong Answer
time: 320ms
memory: 27864kb
input:
500000 392409 161541 72825 120014 449034 320962 490925 62120 211235 236719 211792 410060 31166 20275...
output:
1562980793
result:
wrong answer 1st words differ - expected: '1604788177397380986', found: '1562980793'