#include <iostream>
#include <cstdio>
#include <list>
#include <set>

using namespace std;

const int N=100005;

typedef unsigned long long ulong;
typedef set<int>::iterator itr_t;

int n, k;
int c[N], p[N];
ulong value[N];
set<int> children[N];


ulong dfs(int x)
{
    value[x]=c[x];
    for(itr_t it=children[x].begin(); it!=children[x].end(); it++)
    {
        value[x]+=dfs(*it);
    }
    return value[x];
}

int dfs2(int x)
{
    if(value[x]<=k)
        return x;
    int bestchild=-1;
    for(itr_t it=children[x].begin(); it!=children[x].end(); it++)
    {
        int r=dfs2(*it);
        if(value[r]<=k)
        {
            if(bestchild==-1)
                bestchild=r;
            else if(value[r]>value[bestchild]) bestchild=r;
        }
    }
    return bestchild;
}

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", &c[i]);
    }
    for(int i=2; i<=n; i++)
    {
        scanf("%d", &p[i]);
        children[p[i]].insert(i);
    }

    dfs(1);


    int ctd=0;
    int res=0;
    while(ctd!=1)
    {
        res++;
        ctd=dfs2(1);
        //fprintf(stderr, "deleting %d (value %d)\n", ctd, value[ctd]);
        if(ctd!=1)
        {
            children[p[ctd]].erase(ctd);
            int t=p[ctd];
            while(t)
            {
                value[t]-=value[ctd];
                t=p[t];
            }
        }
        /*fprintf(stderr, "values\n");
        for(int i=1; i<=n; i++)
        {
            fprintf(stderr, "%d: %d\n", i, value[i]);
        }*/

    }
    printf("%d\n", res);
    return 0;
}
