比赛 |
2025.9.13 |
评测结果 |
AAAAAAAAAAAAAAAAAA |
题目名称 |
Vocabulary Quiz |
最终得分 |
100 |
用户昵称 |
左清源 |
运行时间 |
3.060 s |
代码语言 |
C++ |
内存使用 |
12.76 MiB |
提交时间 |
2025-09-13 08:41:12 |
显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
const int N=1e6+10;
int fa[N],n,chk[N],val[N],cnt=1,de[N];
int main(){
freopen("Vocabulary.in","r",stdin);
freopen("Vocabulary.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",fa+i);
cnt++,val[fa[i]]++;
de[i]=de[fa[i]]+1;
if(!chk[fa[i]]){
cnt--;
chk[fa[i]]=1;
}
}
fa[0]=-1;
while(cnt--){
int x;
scanf("%d",&x);
while(x!=-1){
if(val[x]>1)break;
else x=fa[x];
}
if(x==-1){
printf("0\n");
}else{
printf("%d\n",de[x]+1);
val[x]--;
}
}
return 0;
return 0;
}