QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751899 | #9751. 覆盖一棵树 | huang123zs | WA | 1ms | 10064kb | C++14 | 900b | 2024-11-15 21:13:34 | 2024-11-15 21:13:34 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=1.1e6;
inline LL read(){
LL x=0,ff=1;
char c=getchar();
while(!isdigit(c)&&c!='-') c=getchar();
if(c=='-') c=getchar(),ff=-1;
while(isdigit(c)) x=x*10ll+c-'0',c=getchar();
return x*ff;
}
int n;
int head[N],to[N*2],nxt[N*2],tot;
void add_edge(int x,int y){
++tot;
to[tot]=y;
nxt[tot]=head[x];
head[x]=tot;
}
int f[N];
void dfs(int x){
if(!head[x]){
f[x]=0;
return ;
}
f[x]=n+1;
for(int i=head[x];i;i=nxt[i]){
int y=to[i];
dfs(y);
f[x]=min(f[x],f[y]);
}
f[x]++;
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int casecnt=read();
while(casecnt--){
n=read();
for(int i=1;i<=n;++i)
head[i]=0;
tot=0;
for(int i=2;i<=n;++i){
int x=read();
add_edge(x,i);
}
dfs(1);
printf("%d\n",f[1]);
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 10064kb
input:
2 8 1 2 3 2 5 1 7 8 1 2 3 4 5 6 7
output:
2 7
result:
wrong answer 1st lines differ - expected: '3', found: '2'