#include <iostream>
#include <vector>
using namespace std;
const int N = 100000;
vector<int> next_city[N];
long long value[N];
long long path[N];
long long best = 0;

long long find_best(int i, long long time_left)
{
    long long best_t = 0;
    for(auto j : next_city[i])
    {
        if(path[j]<=time_left)
            best_t = max(best_t, value[j] + find_best(j, time_left-path[j]));
    }
    return best_t;
}

int main()
{
    ios_base :: sync_with_stdio(false);
    int n;
    long long t;
    cin >> n >> t;
    for(int i=0; i<n; i++)
        cin >> value[i];
    for(int i=0; i<n; i++)
    {
        int a;
        cin >> a;
        next_city[a-1].push_back(i);
    }
    for(int i=0; i<n; i++)
        cin >> path[i];
    for(int i=0; i<n; i++)
    {
        best = max(best, value[i]+find_best(i,t));
    }
    cout << best;
    return 0;
}