QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#544140 | #6253. Appeal to the Audience | fms | WA | 18ms | 12284kb | C++14 | 618b | 2024-09-02 10:09:32 | 2024-09-02 10:09:32 |
Judging History
answer
#include<bits/stdc++.h>
using I=int;const I N=1e5+10;I a[N],z[N],o[N],tt[N];std::vector<I>g[N];
void dfs1(I u){for(I v:g[u]){dfs1(v);if(z[v]>z[o[u]])o[u]=v;}z[u]=z[o[u]]+1;}
void dfs2(I u,I p){tt[u]=p;if(o[u])dfs2(o[u],p);for(I v:g[u])if(v!=o[u])dfs2(v,v);}
int main(){I n,k;scanf("%d%d",&n,&k);for(I i=1;i<=k;i++)scanf("%d",a+i);for(I i=2;i<=n;i++){I x;scanf("%d",&x);g[x+1].push_back(i);}dfs1(1);dfs2(1,1);
std::vector<I>x;for(I i=2;i<=n;i++)if(tt[i]==i)x.push_back(z[i]);x.push_back(z[1]-1);std::sort(x.begin(),x.end());std::sort(a+1,a+k+1);
I w=0;for(I i=1;i<=k;i++)w+=x[i-1]*a[i];printf("%d\n",w);return 0;}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 6112kb
input:
5 3 5 4 3 0 0 1 1
output:
17
result:
ok single line: '17'
Test #2:
score: 0
Accepted
time: 1ms
memory: 6156kb
input:
11 7 30 5 15 1 3 100 50 0 0 1 0 2 5 2 5 5 1
output:
454
result:
ok single line: '454'
Test #3:
score: -100
Wrong Answer
time: 18ms
memory: 12284kb
input:
99999 50000 776281622 281552176 560818893 743574034 28371581 29065388 861522831 399277410 127891403 337521653 333045937 201722127 532376484 866178821 488930207 533328467 280762095 777881963 698720876 926181033 678638871 483709812 805740065 609341704 534943664 598002301 497944186 842902577 127602924 ...
output:
1506993165
result:
wrong answer 1st lines differ - expected: '74974456112141', found: '1506993165'