QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#713108 | #5455. TreeScript | Wzy | WA | 1ms | 9736kb | C++14 | 966b | 2024-11-05 18:06:33 | 2024-11-05 18:06:34 |
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=1,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);
}
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[4]<<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: 0
Wrong Answer
time: 1ms
memory: 9736kb
input:
2 3 0 1 2 7 0 1 2 2 1 4 1
output:
2 2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'