#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;
typedef vector<pi> vp;
typedef vector<bool> vb;

vi a(200000), p(200000), stepen(200000);
vi e[200000];
map<pi, int> m;
int duzina = 0, sol;
vb see(200000), vis(200000);
int res, k;

void obelezi(int x){
    see[x] = 1;

    for (auto& i : e[x]){
        if (see[i]) continue;
        obelezi(i);
    }
}

vi tmp;
int lepo, duz;
void cik(int x){
    vis[x] = 1;
    lepo += a[x];
    tmp.push_back(x);

    for (auto& i : e[x]){
        if (vis[i]) continue;

        duz += m[{x, i}];
        cik(i);
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);

    int n, t;
    cin >> n >> t;

    for (int i = 1; i <= n; ++i){
        cin >> a[i];
    }

    for (int i = 1; i <= n; ++i){
        cin >> p[i];
        e[p[i]].push_back(i);
    }

    for (int i = 1; i <= n; ++i){
        int x;
        cin >> x;

        m[{p[i], i}] = x;

        stepen[i] = e[i].size();
    }

    for (int i = 1; i <= n; ++i){
        if (see[i]) continue;

        obelezi(i);

        vi cyc;
        tmp.clear();
        cik(i);

        cyc = tmp;
        int len = cyc.size();

        duz += m[{cyc[len - 1], i}];

        int res = lepo * (t / duz);
        t %= duz;

        vi d;
        for (int z = 0; z < 2; ++z){
            for (auto& i : cyc)
                d.push_back(i);
        }
        d.push_back(cyc[0]);
        d.push_back(cyc[1]);

        int li = cyc.size();
        len = d.size();
        vi s(len, 0); //lepota
        vi tt(len, 0); //vreme
        int cc = 1;

        int y = 0, yt = 0;
        for (int i = 1; i < len; ++i){
            s[i] = y + a[d[i]];
            y += a[d[i]];

            yt += m[{d[i - 1], d[i]}];
            tt[i] = yt;
        }

       // for (auto& i : s)
       //     cout << i << ' ';
       // return 0;
       int sol1 = 0;

       vb ok(len + 1, 0);
        for (int i = 1; i < d.size(); ++i){
            if (ok[i]) break;
            ok[i] = 1;

            int l = i, r = len - 1;
            while(l <= r){
                int mid = (l + r) / 2;

                if (tt[mid] - tt[l] > t){
                    r = mid - 1;
                } else {
                    sol1 = max(sol1, s[mid] - s[l - 1]);
                    l = mid + 1;
                }
            }
        }

        sol = max(sol, sol1 + res);
    }

    cout << sol << '\n';
}