#include <cstdlib>
#include <cstdio>
#define gr 100010
#define visa 20
#define ll long long
ll ocena[gr][visa];
int otac[gr][visa];
ll duzina[gr][visa];
int main()
{
    int n;
    ll t;
    scanf("%d%lld",&n,&t);
    for(int i=1;i<=n;++i)scanf("%lld",&ocena[i][0]);
    for(int i=1;i<=n;++i)scanf("%d",&otac[i][0]);
    for(int i=1;i<=n;++i)scanf("%lld",&duzina[i][0]);
    for(int s=1;s<visa;++s)
    {
        for(int i=1;i<=n;++i)
        {
            otac[i][s]=otac[otac[i][s-1]][s-1];
            duzina[i][s]=duzina[i][s-1]+duzina[otac[i][s-1]][s-1];
            ocena[i][s]=ocena[i][s-1]+ocena[otac[i][s-1]][s-1];
        }
    }
    ll res=0;
    for(int i=1;i<=n;++i)
    {
        int c=i;
        ll ovr=t;
        int s=visa-1;
        ll ukoc=0;
        while(true)
        {
            if(duzina[c][s]>ovr)
            {
                if(s==0)break;
                --s;
                continue;
            }
            ukoc+=ocena[c][s];
            ovr-=duzina[c][s];
            c=otac[c][s];
        }
        ukoc+=ocena[c][0];
        if(ukoc>res)res=ukoc;
    }
    printf("%lld\n",res);
    return 0;
}