#include #define debug(x) cerr<<"\tDEBUG: "<<#x<<" = "<<(x)<>=1; p=p*p%P; } return res; } int n,K; int fa[maxn],mark[maxn]; //vectorT[maxn]; bool isnode[maxn]; int dep[maxn]; struct node{ int x; bool operator <(const node &_)const{ return dep[x]T; vectorQ[maxn]; int vis[maxn]; int dis[maxn]; void dfs(int x){ for(int i=0;i>QuQ; while(QuQ--){ cin>>n>>K; for(int i=1;i<=n;i++){ Q[i].clear(); dis[i]=0; isnode[i]=1; vis[i]=0; } dep[1]=1; for(int i=2;i<=n;i++){ scanf("%d",&fa[i]); Q[fa[i]].push_back(i); // T[fa[i]].push_back(i); isnode[fa[i]]=0; } dfs(1); for(int i=1;i<=n;i++){ scanf("%d",&mark[i]); } for(int i=1;i<=n;i++){ if(isnode[i]){ T.push((node){i}); vis[i]=1; } } while(!T.empty()){ node now=T.top(); T.pop(); // debug(now.x); if(now.x==1)continue; if(dis[now.x]!=K){ vis[now.x]=2; if(mark[now.x]){ dis[fa[now.x]]=max(dis[fa[now.x]],dis[now.x]+1); mark[fa[now.x]]=1; } } if(vis[fa[now.x]]==0)T.push((node){fa[now.x]}); vis[fa[now.x]]=1; } int ans=0; for(int i=1;i<=n;i++){ if(vis[i]!=2&&mark[i]){ ans++; } } cout<