Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(114514)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    X=sorted([dp(j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))


Fixed submission:
import sys
import heapq
sys.setrecursionlimit(2*10**5)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    q=[]
    for j in G[i]:
        heapq.heappush(q,-dp(j))
    k=1
    res=0
    while(q):
        x=-heapq.heappop(q)
        res=max(res,x+k)
        k+=1
    return res
print(dp(0))

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(11514)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    X=sorted([dp(j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))


Fixed submission:
import sys
import heapq
sys.setrecursionlimit(2*10**5)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    q=[]
    for j in G[i]:
        heapq.heappush(q,-dp(j))
    k=1
    res=0
    while(q):
        x=-heapq.heappop(q)
        res=max(res,x+k)
        k+=1
    return res
print(dp(0))

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(102030)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    X=sorted([dp(j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))


Fixed submission:
import sys
import heapq
sys.setrecursionlimit(2*10**5)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    q=[]
    for j in G[i]:
        heapq.heappush(q,-dp(j))
    k=1
    res=0
    while(q):
        x=-heapq.heappop(q)
        res=max(res,x+k)
        k+=1
    return res
print(dp(0))

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100030)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    X=sorted([dp(j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))


Fixed submission:
import sys
import heapq
sys.setrecursionlimit(2*10**5)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    q=[]
    for j in G[i]:
        heapq.heappush(q,-dp(j))
    k=1
    res=0
    while(q):
        x=-heapq.heappop(q)
        res=max(res,x+k)
        k+=1
    return res
print(dp(0))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
DP=[-1 for i in range(N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if DP[i]!=-1:
        return DP[i]
    if len(G[i])==0:
        DP[i]=0
        return 0
    X=sorted([(dp(j),j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i][0]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))

Fixed submission:
import sys
import heapq
sys.setrecursionlimit(2*10**5)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    q=[]
    for j in G[i]:
        heapq.heappush(q,-dp(j))
    k=1
    res=0
    while(q):
        x=-heapq.heappop(q)
        res=max(res,x+k)
        k+=1
    return res
print(dp(0))

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5+10)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
DP=[-1 for i in range(N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if DP[i]!=-1:
        return DP[i]
    if len(G[i])==0:
        DP[i]=0
        return 0
    X=sorted([(dp(j),j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i][0]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))

Fixed submission:
import sys
import heapq
sys.setrecursionlimit(2*10**5)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    q=[]
    for j in G[i]:
        heapq.heappush(q,-dp(j))
    k=1
    res=0
    while(q):
        x=-heapq.heappop(q)
        res=max(res,x+k)
        k+=1
    return res
print(dp(0))

Buggy python submission (verdict: Runtime Error):
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
DP=[-1 for i in range(N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if DP[i]!=-1:
        return DP[i]
    if len(G[i])==0:
        DP[i]=0
        return 0
    X=sorted([(dp(j),j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i][0]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))

Fixed submission:
import sys
import heapq
sys.setrecursionlimit(2*10**5)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    q=[]
    for j in G[i]:
        heapq.heappush(q,-dp(j))
    k=1
    res=0
    while(q):
        x=-heapq.heappop(q)
        res=max(res,x+k)
        k+=1
    return res
print(dp(0))