#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 100000;
vector<int> next_city[N];
long long value[N];
long long path[N];
//vector<pair<long long,long long>> best_path[N];
vector<pair<int, long long>> ciklusi[N];
vector<long long> ciklusi_vreme[N];
//bool visited[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)
            return value[j] + find_best(j, time_left-path[j]);
    }
    return 0;
}
void best_c(int i, int poc, long long t, long long v)
{
    //visited[i] = true;
    for(auto j : next_city[i])
    {
        ciklusi[poc].push_back({j,v});
        ciklusi_vreme[poc].push_back(t);

        if(j==poc)
            return;

        best_c(j,poc,t+path[j],v+value[j]);
    }
}



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];
    if(n<=1000)
    {
        for(int i=0; i<n; i++)
        {
            best = max(best, value[i]+find_best(i,t));
        }
        cout << best;
    }
    else
    {
        for(int i=0; i<n; i++)
        {
            best_c(i,i,0,value[i]);
            long long timee = (t/ciklusi_vreme[i].back());
            long long time_mod = t % ciklusi_vreme[i].back();
            long long bbest = timee*ciklusi[i].back().second;
            int j = upper_bound(ciklusi_vreme[i].begin(), ciklusi_vreme[i].end(), time_mod)- ciklusi_vreme[i].begin();
            bbest+= ciklusi[i][j-1].second;
            best = max(best, bbest);
        }
        cout << best;
    }
    return 0;
}