#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
using namespace std;
const int NMAX=5e5+7;

int n, a[NMAX], d[NMAX], x[NMAX], out[NMAX];
ll T, res, ans;
vector<pii> g[NMAX];

ll Dfs(int son, ll vreme)
{
    if(vreme<0) return 0;
    if(vreme>=0 && !out[son]) return a[son];
    ll res1=0;
    for(pii i:g[son])
    {
        res1=max(res1,Dfs(i.F, vreme-1LL*i.S)+a[son]);
    }
    return res1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n>>T;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>x[i];
    for(int i=1;i<=n;i++) cin>>d[i];
    for(int i=1;i<=n;i++) g[x[i]].push_back({i, d[i]}), out[x[i]]++;
    for(int i=1;i<=n;i++)
    {
        res=Dfs(i,T);
        ans=max(ans, res);
    }
    cout<<ans<<endl;
    return 0;
}