#include <cstdlib>
#include <iostream>
#include <vector>
#include <stdio.h>

using namespace std;

struct node
{
    int val,parent,time,price;
    vector<int> c;
};

int n,k;
node firma[100000];

bool cmp(int a, int b)
{
    if(firma[a].time>firma[b].time) return true;
    if(firma[a].time==firma[b].time && firma[a].price<firma[b].price) return true;
    return false;
}

int main(int argc, char *argv[])
{
    FILE *in;
    FILE *out;
    in=fopen("porez.in","r");
    out=fopen("porez.out","w");
    fscanf(in,"%d",&n);
    fscanf(in,"%d",&k);
    for(int i=0; i<n; i++) fscanf(in,"%d",&firma[i].val);
    for(int i=1; i<n; i++)
     {
         fscanf(in,"%d",&firma[i].parent);
         firma[i].parent--;
         firma[firma[i].parent].c.push_back(i);
     }
    /*for(int i=0; i<n; i++)
     {
         printf("%d->%d: %d\n",firma[i].parent,i,firma[i].val);
         for(int j=0; j<firma[i].c.size(); j++) printf("%d ",firma[i].c[j]);
         printf("\n");
     }*/
    for(int i=n-1; i>=0; i--)
     {
         sort(&firma[i].c[0],&firma[i].c[firma[i].c.size()],cmp);
         /*for(int j=0; j<firma[i].c.size(); j++) printf("%d ",firma[i].c[j]);
         printf("\n");*/
         int r=k-firma[i].val;
         int time=1,price=firma[i].val;
         int j=0;
         while(j<firma[i].c.size() && r>=firma[firma[i].c[j]].price)
          {
              r-=firma[firma[i].c[j]].price;
              price+=firma[firma[i].c[j]].price;
              time=max(time,firma[firma[i].c[j]].time);
              j++;
          }
         while(j<firma[i].c.size())
          {
              time+=firma[firma[i].c[j]].time;
              j++;
          }
         firma[i].time=time;
         firma[i].price=price;
         //printf("%d: %d %d\n",i,firma[i].price,firma[i].time);
     }
    fprintf(out,"%d\n",firma[0].time);
    fclose(in);
    fclose(out);
    system("PAUSE");
    return 0;
}
