n,q=map(int,input().split())
P=list(map(int,input().split()))
S=list(map(int,input().split()))
V=list(map(int,input().split()))
G=[[] for _ in range(n)]
for i in range(n-1):
    G[P[i]-1].append(i+1)
Q=[0]
D=[0]*n
while Q:
    h=Q.pop(0)
    for a in G[h]:
        Q.append(a)
        D[a]=D[h]+1
for v in V:
    print(D[v-1])
    