# 6 2 3
# 2 1
# 3 4 5 6 1
# 2 3 4 5 6
import collections
n,m,d = map(int,input().strip().split())
l = list(map(int,input().strip().split()))
w = list(map(int,input().strip().split()))
a = collections.defaultdict(int) # child -> father
b = collections.defaultdict(int) # father -> child
for i in range(n-1):
a[i+2] = w[i]
b[w[i]] = i+2
res = []
for i in range(m):
new = [l[i]]
level = 0
now = l[i]
while a[now] != 0 and level < d:
new.append(a[now])
level += 1
now = a[now]
level = 0
now = l[i]
while b[now] != 0 and level < d:
new.append(b[now])
level += 1
now = b[now]
if i==0:
res.extend(new)
else:
res = [x for x in res if x in new]
#print(res)
print(len(res))
#滴滴##笔试题目#