QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#713052 | #5455. TreeScript | Wzy | WA | 15ms | 9700kb | C++14 | 1.0kb | 2024-11-05 17:57:36 | 2024-11-05 17:57:36 |
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;
vector<int> tmp;
for(int i=h[u];~i;i=ne[i]){
int j=e[i];
t++;
dfs(j);
tmp.push_back(d[j]);
}
sort(tmp.begin(),tmp.end());
int mx=1;
for(int i=0;i<tmp.size();i++){
if(i==tmp.size()-1) mx=max(mx,tmp[i]);
else mx=max(mx,d[i]+1);
}
d[u]=mx;
}
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[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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9700kb
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: -100
Wrong Answer
time: 15ms
memory: 5924kb
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:
3 5 7 11 13 15 19 22 23 27 29 32 36 40 42 45 49 52 54 57 61 62 65 70 74 76 80 82 85 89 90 94 97 98 101 104 105 107 108 111 114 117 119 121 124 126 130 135 137 139 142 143 146 150 154 157 160 162 164 167 170 172 174 177 178 180 182 184 190 194 197 201 205 207 210 214 216 217 221 1 1 222 225 228 229 2...
result:
wrong answer 1st numbers differ - expected: '4', found: '3'