#include<iostream>
#include<stdio.h>
#include<queue>
#include<deque>
#include<stdlib.h>
#include<algorithm>
#include<utility>
#include<stack>
#include<set>
#include<cstring>
#include<vector>
using namespace std;

int n;
long int k;
int ANS=0;
long int v[100055];
int par[100555];
int nivo[100055];
int brsin[100055];
long long int dp[100055];
bool mark[100055];
queue<int> Q;
queue<int> child[100055];
pair<int,int> MLATAC[100055];

void BFS(int x)
{
   Q.push(x);
   while (!Q.empty())
   {
         int tmp=Q.front();
         mark[tmp]=true;
         nivo[tmp]=nivo[par[tmp]]+1;
         Q.pop();
         while (!child[tmp].empty())
         {
               int tmp2=child[tmp].front();
               child[tmp].pop();
               if (!mark[tmp2]) 
               {
                    Q.push(tmp2);
                    mark[tmp2]=true;
                    nivo[tmp2]=nivo[par[tmp2]]+1;            
               }  
         }
         
         
   }
}

int main()
{
    freopen("porez.in","r",stdin);
    freopen("porez.out","w",stdout);
    scanf("%d %d",&n,&k);
    for (int i=1;i<=n;i++) 
    {
        scanf("%d",&v[i]);
        dp[i]=v[i];
    }
    par[1]=0;
    par[0]=100008;
    nivo[0]=0;
    brsin[0]=1;
    for (int i=1;i<=n-1;i++)
    {
        int br;
        scanf("%d",&br);
        par[i+1]=br;
        child[br].push(i+1);
    }
    for (int i=1;i<=n;i++)
    {
        brsin[i]=child[i].size();
    }
    BFS(1);
    for (int i=1;i<=n;i++) 
    {
        MLATAC[i].first=nivo[i];
        MLATAC[i].second=i;
    }
    sort(MLATAC+1,MLATAC+n+1);
    
    for (int i=n;i>=0;i--)
    {
        if ((dp[MLATAC[i].second]>k) || (i==0))
        {  
        
                      ANS+=brsin[MLATAC[i].second];
                     
                      dp[MLATAC[i].second]=v[MLATAC[i].second];
                      
        }
        dp[par[MLATAC[i].second]]+=dp[MLATAC[i].second];
    }
    cout<<ANS<<endl;
    return 0;
}
