#include <iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;


int lep[100005],pa[100005],pb[100005];
struct maca{int c,d;};
vector<maca> mg[100005];

int vc,u,lc,tb[100005],s[100005],marka[100005];

int dfs(int cvor,int t)
{
    int i,x,r=0;

    for(i=0;i<mg[cvor].size();i++)
    {
        x=mg[cvor][i].c;
        if(t>=mg[cvor][i].d)  r=max(r,dfs(x,t-mg[cvor][i].d)+lep[cvor]);
    }

    if(r==0) r=lep[cvor];
    return r;
}

void tfs(int cvor)
{
    int i,x;   marka[cvor]=1;  lc+=lep[cvor];  u++; tb[u]=cvor;

    for(i=0;i<mg[cvor].size();i++)
    {
        x=mg[cvor][i].c;

        //cout<<"tunj  "<<x<<" ";
        s[u]=mg[cvor][i].d;  vc+=mg[cvor][i].d;
        //cout<<u<<" "<<s[u]<<endl;
        if(marka[x]==0) tfs(x);
    }
}

int main()
{
    ios::sync_with_stdio(false);

    int n,t,i,j,x,y,res=0,ostalo,suma,a,lll,rrr;
    maca mjau;

    cin>>n>>t;
    for(i=1;i<=n;i++) cin>>lep[i];

    for(i=1;i<=n;i++) cin>>pa[i];
    for(i=1;i<=n;i++) cin>>pb[i];

    for(i=1;i<=n;i++)
    {
        x=pa[i]; y=pb[i];
        mjau.c=i; mjau.d=y;

        mg[x].push_back(mjau);
    }


    if(n<=1000 && t<=1000) //prvi podzadatak
    {
       for(i=1;i<=n;i++) res=max(res,dfs(i,t));
    }
    else  //treci podz
    {

      for(i=1;i<=n;i++)
       {
         if(marka[i]==0)
         {
              vc=0; lc=0; tfs(i);

             //cout<<"ispis "<<u<<" "<<vc<<" "<<lc<<endl;

             //for(j=1;j<=u;j++) cout<<tb[j]<<" "<<s[j]<<endl;



            a=1;  suma=0;  lll=0;
            for(j=1;j<=u;j++)
            {
                ostalo=t%vc;
                while(1)
                {
                  if(a==u+1) a=1;



                 // cout<<"sumaaaaaaaaaaaaaaaaaaaaaa "<<suma<<endl;

                  if(suma+s[a]<=ostalo)  {suma+=s[a];  lll+=lep[tb[a]];}
                  else
                  {
                      //cout<<j<<" odgovorrrr "<<lll<<endl;
                     // lll+=lep[tb[a]];
                    res=max(res,(t/vc)*lc+lll+lep[tb[a]]); break;
                  }
                  a++;

                  //cout<<j<<" a je "<<a<<endl;  //getchar();
                }

               suma-=s[j];  lll-=lep[tb[j]];  // lll-=lep[tb[j+1]];

               //cout<<"sada "<<suma<<" "<<lll<<" "<<a<<endl;
            }
         }

        // cout<<"iiiiiiiii"<<i<<endl;

       }
    }

    cout<<res;

    /*
    5 7
    7 3 1 4 8
    4 3 5 2 1
    3 2 4 1 7

    6 200
    1 1 1 1 1 100
    3 1 2 5 4 5
    1 1 1 10 10 1

    */


    return 0;
}