#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], sled[25][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;
}

ll dp[NMAX], dpa[NMAX];

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]]++;
    int cikl=1;
    for(int i=1;i<=n;i++) if(out[i]!=1) cikl=0;
    if(cikl)
    {
        int idi=1;
        ll tmp=0;
        ll tmpa=a[idi];
        int svi=0;
        for(;idi!=1;idi=g[idi][0].F)
        {
            dp[++svi]=tmp;
            dpa[svi]=tmpa;
            tmp+=1LL*g[idi][0].S;
            tmpa+=1LL*a[g[idi][0].S];
        }
        //for(int i=1;i<25;i++) for(int j=1;j<=n;j++) sled[i][j]=sled[i-1][sled[i-1][j]];
        for(;idi!=1;idi=g[idi][0].F)
        {
            dp[++svi]=tmp;
            dpa[svi]=tmpa;
            tmp+=1LL*g[idi][0].S;
            tmpa+=1LL*a[g[idi][0].S];
        }
        tmp/=2;
        tmpa/=2;
        ll br=T/tmp;
        ll ost=T%tmp;
        ll svakako=br*tmpa;
        ll jos=0;
        for(int i=1;i<=n;i++)
        {
            int idedo=upper_bound(dp+1,dp+n+1, dp[i]+ost)-dp;
            --idedo;
            jos=max(jos, dpa[idedo]-dpa[i-1]);
        }
        cout<<svakako+jos<<endl;
    }
    else
    {
        for(int i=1;i<=n;i++)
    {
        res=Dfs(i,T);
        ans=max(ans, res);
    }
    cout<<ans<<endl;
    }
    return 0;
}