728x90
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
n=int(input())
parent=list(map(int, input().split()))
deleteNode=int(input())
tree = [[] for _ in range(n)]
root=0
for i in range(n):
if parent[i]!=-1:
tree[parent[i]].append(i)
tree[i].append(parent[i])
else:
root=i
visited = [False]*(n+1)
cnt=0
def dfs(v):
global cnt
visited[v] = True
cNode=0
for i in tree[v]:
if not visited[i] and i!=deleteNode:
cNode+=1
dfs(i)
if cNode==0:
cnt+=1
if deleteNode==root:
print(0)
else:
dfs(root)
print(cnt)
728x90