#include <bits/stdc++.h>
#define PRINT(x) cerr<<#x<<"="<<x<<endl
#define pii pair<int,int>
#define fi first
#define se second
#define mid (l+r)/2
#define pb push_back
#define lld long long
#define LINF 1000000000000000LL
using namespace std;
#define MAXN 100010
#define MAXL 40
int N;
lld T, v[MAXN], dist[MAXN][MAXL], val[MAXN][MAXL], anc[MAXN][MAXL], rez, p[MAXN], d[MAXN];
lld calc(int node, lld st[MAXN][MAXL], lld X) {
    lld rez = 0;
    for(int d = 0; d < MAXL; d++) {
        //PRINT(X);
        //PRINT(node);
        //PRINT(d);
        //PRINT(st[node][d]);
        if(X&(1LL<<d)) rez += st[node][d], node = anc[node][d];
    }
    return rez;
}
lld bs(int node) {
    lld l = 0, r = T, rez = 0;
    while(l <= r) {
        //PRINT(mid);
        //PRINT(calc(node, dist, mid));
        if(calc(node, dist, mid) <= T) rez = mid, l = mid+1;
        else r = mid-1;
    }
    return rez;
}
int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
    cin >> N >> T;
    for(int i = 1; i <= N; i++) cin >> v[i];
    for(int i = 1; i <= N; i++) cin >> p[i];
    for(int i = 1; i <= N; i++) cin >> d[i];
    for(int i = 1; i <= N; i++) anc[i][0] = p[i], dist[i][0] = d[i], val[i][0] = v[p[i]];
    for(int d = 1; d < MAXL; d++) {
        for(int i = 1; i <= N; i++) {
            anc[i][d] = anc[anc[i][d-1]][d-1];
            lld distt = dist[i][d-1] + dist[anc[i][d-1]][d-1];
            //PRINT(i);
            //PRINT(d);
            //PRINT(distt);
            dist[i][d] = (distt > T ? LINF:distt);
            val[i][d] = val[i][d-1] + val[anc[i][d-1]][d-1];
        }
    }
    for(int i = 1; i <= N; i++) {
        lld X = bs(i);
        //PRINT(i);
        //PRINT(X);
        //PRINT(v[i] + calc(i, val, X));
        rez = max(rez, v[i] + calc(i, val, X));
    }
    cout << rez;
    return 0;
}