blog.encrypted.gg/130 의 도움을 받아 풀 수 있었습니다.
from collections import deque
import sys
N = int(input())
parent = list(map(int, input().split()))
sibling = [[] for _ in range(N+1)]
root = -1
for i in range(N):
if parent[i] == -1:
root = i
else:
sibling[parent[i]].append(i)
del_node = int(input())
if del_node == root:
print(0)
sys.exit()
Q = deque()
Q.append(root)
cnt = 0
while Q:
cur = Q.popleft()
if len(sibling[cur]) == 0 or (len(sibling[cur]) == 1 and sibling[cur][0] == del_node):
cnt += 1
for next in sibling[cur]:
if next != del_node:
Q.append(next)
print(cnt)