#include <bits/stdc++.h>
#define maxN 100005

using namespace std;

long long dp[1005][1005],n,t,i,j,k,x[maxN],d[maxN],a[maxN],ans,dis,s,res,spar[3][maxN][44];
vector < pair<int,int> > adj[maxN],adjt[maxN];
vector <int> v;

long long resi(int n,int t){
if(t<spar[2][n][0]) return 0;
for(j=0;j<=40;j++){
    if(spar[2][n][j+1]>t){
        //cout<<n<<" "<<t<<" "<<spar[1][n][j]+resi(spar[0][n][j],t-spar[2][n][j])<<endl;
        return spar[1][n][j]+resi(spar[0][n][j],t-spar[2][n][j]);
    }
}
}

int main()
{
    cin>>n>>t;
    for(i=0;i<n;i++){
        cin>>a[i];
        s+=a[i];
    }
    for(i=0;i<n;i++){
        cin>>x[i];
        x[i]--;
    }
    for(i=0;i<n;i++){
        cin>>d[i];
        dis+=d[i];
    }
    for(i=0;i<n;i++){
        adj[x[i]].push_back({i,d[i]});
        adjt[i].push_back({x[i],d[i]});
    }
    if(false){
    for(i=0;i<=t;i++){
        for(j=0;j<n;j++){
            dp[i][j]=a[j];
            for(k=0;k<adj[j].size();k++){
                if(i>=adj[j][k].second){
                    dp[i][j]=max(dp[i][j],a[j]+dp[i-adj[j][k].second][adj[j][k].first]);
                }
            }
            ans=max(ans,dp[i][j]);
        }
    }
    }
    else{
        for(i=0;i<n;i++){
            spar[0][i][0]=adjt[i][0].first;
            spar[1][i][0]=a[adjt[i][0].first];
            spar[2][i][0]=adjt[i][0].second;
        }
        for(j=1;j<=40;j++){
            for(i=0;i<n;i++){
                spar[0][i][j]=spar[0][spar[0][i][j-1]][j-1];
                spar[1][i][j]=spar[1][i][j-1]+spar[1][spar[0][i][j-1]][j-1];
                spar[2][i][j]=spar[2][i][j-1]+spar[2][spar[0][i][j-1]][j-1];
            }
        }
        ans=0;
        for(i=0;i<n;i++){
            ans=max(ans,a[i]+resi(i,t));
        }
    }
    cout<<ans<<endl;
    return 0;
}