import typing class DSU: ''' Implement (union by size) + (path halving) Reference: Zvi Galil and Giuseppe F. Italiano, Data structures and algorithms for disjoint set union problems ''' def __init__(self, n: int = 0) -> None: self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: assert 0 <= a < self._n assert 0 <= b < self._n x = self.leader(a) y = self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a: int, b: int) -> bool: assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a: int) -> int: assert 0 <= a < self._n parent = self.parent_or_size[a] while parent >= 0: if self.parent_or_size[parent] < 0: return parent self.parent_or_size[a], a, parent = ( self.parent_or_size[parent], self.parent_or_size[parent], self.parent_or_size[self.parent_or_size[parent]] ) return a def size(self, a: int) -> int: assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self) -> typing.List[typing.List[int]]: leader_buf = [self.leader(i) for i in range(self._n)] result: typing.List[typing.List[int]] = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return list(filter(lambda r: r, result)) from collections import deque n,k=map(int, input().split()) p=list(map(lambda x: int(x)-1, input().split())) a=list(map(int, input().split())) indeg=[0]*n uf=DSU(n) is_root=[False]*n is_root_next=[False]*n for v in range(n): if uf.same(v, p[v]): is_root[v]=True is_root_next[p[v]]=True else: indeg[p[v]]+=1 uf.merge(v, p[v]) ans=[False]*(2*n+1) dp=[[0 for _ in range(2*n+1)] for _ in range(n)] size=[1]*n ans_size=0 groups=uf.groups() ans[0]=True for group in groups: queue=deque() for v in group: if indeg[v]==0: queue.appendleft(v) for c_v in [0,1]: for c_p in [0,1]: for c_s in [0,1]: dp[v][c_v+(a[v]+c_v+c_p)%2]|=1<<(4*c_v+2*c_p+c_s) while len(queue)>0: v=queue.pop() if is_root[v]: dp_p=[False]*(2*(size[v]+ans_size)+1) for i in range(2*size[v]+1): for c_v in [0,1]: for c_p in [0,1]: for j in range(2*ans_size+1): dp_p[i+j]|=(dp[v][i]>>(4*c_v+3*c_p))&ans[j]&1 ans_size+=size[v] for i in range(2*ans_size+1): ans[i]=dp_p[i] else: dp_p=[0 for _ in range(2*(size[v]+size[p[v]])+1)] for i in range(2*size[v]+1): for c_v in [0,1]: for c_p in [0,1]: for c_pp in [0,1]: for j in range(2*size[p[v]]+1): if is_root_next[v]: dp_p[i+j]|=((dp[v][i]>>(5*c_v+2*c_p))&(dp[p[v]][j]>>(4*c_p+2*c_pp+c_v))&1)<<(4*c_p+2*c_pp+c_v) else: for c_s in [0,1]: dp_p[i+j]|=((dp[v][i]>>(4*c_v+2*c_p+c_s))&(dp[p[v]][j]>>(4*c_p+2*c_pp+c_s))&1)<<(4*c_p+2*c_pp+c_s) size[p[v]]+=size[v] for i in range(2*size[p[v]]+1): dp[p[v]][i]=dp_p[i] indeg[p[v]]-=1 if indeg[p[v]]==0: queue.appendleft(p[v]) print("Yes" if ans[k] else "No")