QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#787112 | #9751. 覆盖一棵树 | fatesrl# | WA | 11ms | 3760kb | C++20 | 736b | 2024-11-27 09:52:58 | 2024-11-27 09:52:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
vector mp(0,vector (0,0));
vector deep(0,0);
int mxd=0;
void dfs(int d,int fa){
for(auto x:mp[d]){
if(x==fa) continue;
deep[x]=deep[d]+1;
if(deep[x]>deep[mxd]) mxd=x;
dfs(x,d);
}
}
void solve(){
int n;
cin>>n;
mp.assign(n+1,vector<int>(0));
for(int i=2;i<=n;i++){
int x;
cin>>x;
mp[x].push_back(i);
// mp[i].push_back(x);
}
mxd=1;
deep.assign(n+1,0);
deep[1]=0;
dfs(1,0);
// int tp=mxd;
// deep[tp]=1;
// deep.assign(n+1,0);
// dfs(tp,0);
// cout<<tp<<' '<<mxd<<' '<<deep[mxd]<<'\n';
cout<<deep[mxd]<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int ins=1;
cin>>ins;
while(ins--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3760kb
input:
2 8 1 2 3 2 5 1 7 8 1 2 3 4 5 6 7
output:
3 7
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 11ms
memory: 3608kb
input:
33428 10 1 2 3 3 4 6 7 7 9 10 1 2 3 4 5 6 7 8 8 8 1 2 3 4 5 6 7 8 1 2 3 4 4 6 7 4 1 2 3 3 1 2 3 1 1 9 1 2 3 4 5 6 7 8 2 1 3 1 2 10 1 2 3 4 5 6 7 8 9 3 1 2 2 1 10 1 2 3 4 5 6 7 8 9 2 1 5 1 2 2 4 8 1 2 3 4 5 6 7 5 1 2 3 3 2 1 5 1 2 3 4 3 1 2 9 1 2 3 4 5 6 6 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 5 7 8 8 1 2 ...
output:
7 8 7 6 3 2 1 8 1 2 9 2 1 9 1 3 7 3 1 4 2 7 8 7 6 4 1 2 9 7 4 3 4 6 7 3 5 7 6 5 9 3 4 4 8 2 8 6 2 4 8 4 2 1 5 2 5 2 4 7 2 2 5 2 2 6 3 9 2 5 7 4 2 2 1 3 1 9 1 5 1 7 3 6 2 9 7 2 3 1 3 3 1 2 8 6 8 4 7 7 7 6 5 7 8 4 5 2 5 5 1 7 7 7 2 2 2 3 8 3 5 6 4 3 3 3 2 2 4 8 6 7 8 6 4 2 4 7 8 1 6 2 7 7 9 1 2 8 5 2 ...
result:
wrong answer 1st lines differ - expected: '4', found: '7'