노트

[백준] 13237번 Binary tree python 본문

알고리즘

[백준] 13237번 Binary tree python

_Myway 2024. 3. 1. 14:06
n = int(input())
parent = [int(input()) for _ in range(n)]
high = [0 for i in range(n)]

for i in range(n):
    if parent[i]==-1:
        continue
    high[i]=high[parent[i]-1]+1

for i in range(n):
    print(high[i])
Comments