QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#713113 | #5455. TreeScript | Wzy | TL | 12ms | 7684kb | C++14 | 989b | 2024-11-05 18:08:09 | 2024-11-05 18:08:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=1e5+10,M=1e6+10;
const int mod=1e9+7;
int INF = 1e9;
int p[N];
int h[N],ne[M],e[M],idx;
int d[N];
LL res;
void add(int a,int b){
e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
void dfs(int u){
int t=0;
int mx1=0,mx2=0;
for(int i=h[u];~i;i=ne[i]){
int j=e[i];
t++;
dfs(j);
if(d[j]>mx1) mx2=mx1,mx1=d[j];
else if(d[j]>mx2) mx2=d[j];
}
d[u]=max(mx1,mx2+1);
if(!d[u]) d[u]=1;
}
void solve(){
res=0;
int n;
cin>>n;
for(int i=0;i<=n;i++) h[i]=-1;
idx=0;
for(int i=1;i<=n;i++) {
int p;
cin>>p;
add(p,i);
}
dfs(1);
//cout<<d[3]<<endl;
cout<<d[1]<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1;
cin>>T;;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5604kb
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: 0
Accepted
time: 12ms
memory: 7684kb
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:
4 4 3 4 3 4 5 5 4 4 4 4 5 5 3 4 4 5 3 5 5 3 5 4 5 4 5 3 4 5 2 5 4 3 5 5 4 3 3 4 4 4 3 3 4 4 5 5 4 4 4 2 4 5 5 4 4 5 4 4 5 4 3 4 4 4 4 4 5 4 4 5 5 4 5 5 2 3 4 1 1 5 5 4 3 4 5 5 4 5 4 4 4 4 4 4 4 4 4 4 5 4 4 6 5 5 3 3 5 3 4 3 3 3 4 4 3 2 4 4 3 5 3 5 3 4 4 4 5 4 5 4 5 4 4 3 5 4 4 3 3 3 3 2 5 5 4 2 4 5 ...
result:
ok 1000 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
1 200000 0 1 2 1 4 2 3 4 1 7 9 3 4 13 9 15 11 7 7 14 5 11 16 1 5 21 11 11 6 4 23 27 22 32 24 35 28 3 8 31 18 4 32 38 39 23 37 37 13 1 35 30 20 3 39 36 46 6 14 20 37 3 2 23 56 43 34 10 58 49 67 49 9 69 48 65 37 12 8 6 47 44 36 7 50 15 29 12 53 26 66 47 43 64 29 69 41 13 1 20 52 21 51 100 33 79 58 76 ...