#include <bits/stdc++.h>
using namespace std;

int n,anc[100005];
long long t,rating[200005],in,res,ln[200005],csz,csc;
vector<pair<int,long long>> graph[200005],got[200005];
bool test_case4=true,visited[200005],free_cycle[200005],active[200005];
int visited2[200005],visited3[200005];
queue<int> snake;

void solve(int cur)
{
    if(visited2[cur]==1)
    {
        return;
    }
    visited2[cur]=1;
    for(auto i:graph[cur])
    {
        solve(i.first);
    }
}

void brute(int cur,long long len,long long score)
{
    if(len>t)
    {
        return;
    }
    score+=rating[cur];
    if(visited3[cur]!=0)
    {
        res=max(res,score+(t-len)/(len-visited2[cur])*(score-visited3[cur]));
        return;
    }
    visited2[cur]=len;
    visited3[cur]=score;
    res=max(res,score);
    for(auto i:graph[cur])
    {
        brute(i.first,len+i.second,score);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>t;
    for(int i=1;i<=n;i++)
    {
        cin>>rating[i];
        rating[i+n]=rating[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>anc[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>in;
        graph[anc[i]].push_back({i,in});
        graph[anc[i]+n].push_back({i+n,in});
    }
    for(int i=1;i<=n;i++)
    {
        if(graph[i].empty() || graph[i].size()!=1)
        {
            test_case4=false;
            break;
        }
    }
    if(test_case4)
    {
        for(int i=1;i<=n;i++)
        {
            if(visited[i])
            {
                continue;
            }
            long long cyc_size=0,cyc_score=0,res1=0,cur_size=0,cur_score=0;
            int cur=i;
            while(!visited[cur])
            {
                visited[cur]=true;
                cyc_size+=graph[cur][0].second;
                cyc_score+=rating[cur];
                cur=graph[cur][0].first;
            }
            while(!snake.empty())
            {
                snake.pop();
            }
            cur=i;
            cur_score=rating[cur];
            snake.push(cur);
            while(visited2[cur]!=2)
            {
                visited2[cur]++;
                while(cur_size>t%cyc_size)
                {
                    cur_size-=graph[snake.front()][0].second;
                    cur_score-=rating[snake.front()];
                    snake.pop();
                }
                res1=max(cur_score,res1);
                cur_score+=rating[graph[cur][0].first];
                cur_size+=graph[cur][0].second;
                cur=graph[cur][0].first;
                snake.push(cur);
            }
            res=max(res,res1+t/cyc_size*cyc_score);
        }
        cout<<res;
        return 0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int i=1;i<=n;i++)
        {
            visited2[i]=0;
            visited3[i]=0;
        }
        brute(i,0,0);
    }
    cout<<res;
}