QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#176897 | #5455. TreeScript | Cidoai# | WA | 4ms | 3292kb | C++14 | 995b | 2023-09-12 09:38:26 | 2023-09-12 09:38:26 |
Judging History
answer
#include<cstdio>
inline int read(){
int x=0;
int f=0,ch=0;
while(ch<48||ch>57) f=(ch=='-'),ch=getchar();
while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar();
return f?-x:x;
}
inline void write(int x,char end=' '){
if(x==0){
putchar('0');
putchar(end);
return;
}
if(x<0) putchar('-'),x=-x;
int ch[70]={0},cnt=0;
while(x){
ch[cnt++]=(int)(x%10);
x/=10;
}
while(cnt--) putchar(ch[cnt]+48);
putchar(end);
}
inline int max(int x,int y){return x>y?x:y;}
const int N=2e5+5;
int p[N],dep[N],flag[N],sum[N],leaf[N];
int main(){
int T=read();
while(T--){
int n=read();
for(int i=1;i<=n;++i){
p[i]=read();
dep[i]=dep[p[i]]+1;
if(!flag[p[i]]) sum[dep[p[i]]]++;
flag[p[i]]=1;
}
for(int i=1;i<=n;++i){
if(!flag[i]){
leaf[dep[i]]=1;
}
}
int ans=1;
for(int i=1;i<=n;++i) ans=max(ans,sum[i]+leaf[i]);
for(int i=1;i<=n;++i) flag[i]=sum[i]=leaf[i]=0,dep[i]=p[i]=0;
write(ans,'\n');
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3292kb
input:
2 3 0 1 2 7 0 1 2 2 1 4 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 1336kb
input:
1000 197 0 1 1 2 1 4 1 5 8 3 5 1 4 7 12 14 4 7 10 9 12 11 16 10 21 19 22 17 25 13 28 9 5 15 26 26 33 25 15 1 35 6 32 17 37 8 19 43 19 27 29 9 30 6 31 27 35 35 37 13 28 38 57 31 38 8 22 14 33 9 18 62 52 37 10 19 22 60 54 12 38 59 64 65 80 82 28 60 85 78 27 25 71 14 52 6 59 14 87 32 33 41 59 41 88 38 ...
output:
23 12 4 13 9 13 32 37 8 19 13 15 59 38 7 9 30 76 9 38 65 5 21 26 28 15 68 7 13 45 4 33 11 7 36 14 6 10 8 13 18 16 9 5 12 11 43 46 11 13 16 4 10 33 52 19 20 27 11 23 36 27 4 25 22 18 8 23 42 18 11 57 50 18 23 38 4 5 24 1 1 57 36 9 9 9 33 65 15 26 22 29 18 15 9 10 11 10 17 25 24 28 15 75 24 33 4 4 34 ...
result:
wrong answer 1st numbers differ - expected: '4', found: '23'