unittest
{
	assert( [ "5 2", "2 4 5 1 3", "3 4 -10 -8 8" ].solve == 8 );
	assert( [ "2 3", "2 1", "10 -7" ].solve == 13 );
	assert( [ "3 3", "3 1 2", "-1000 -2000 -3000" ].solve == -1000 );
	assert( [ "10 58", "9 1 6 7 8 4 3 2 10 5", "695279662 988782657 -119067776 382975538 -151885171 -177220596 -169777795 37619092 389386780 980092719" ].solve == 29507023469 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	ps[] -= 1;
	input.popFront;
	auto cs = input.front.split.to!( long[] );
	
	// １ループの合計スコアを計算
	auto uft = UnionFindTree( n );
	long[ long ] ts;
	foreach( i; 0L .. n )
	{
		uft.unite( i, ps[ i ] );
	}
	foreach( i; 0L .. n )
	{
		ts[ uft.root( i ) ] += cs[ i ];
	}
	
	// スコアの最大値を計算
	auto ans = long.min;
	foreach( i; 0L .. n )
	{
		auto lw = uft.weight( i );
		auto lc = k / lw;
		auto lr = k % lw;
		auto lt = ts[ uft.root( i ) ];
		
		auto t = 0L;
		ans = max( ans, lt * lc );
		for( auto j = 1L, p = ps[ i ]; p != i; j++, p = ps[ p ] )
		{
			if( k < j ) break;
			t += cs[ p ];
			ans = max( ans, t, t + lt * ( lc - ( lr < j ) ) );
		}
	}
	return ans;
}

// UnionFind木
struct UnionFindTree
{
	long[] ps;
	long[] rs;
	long   rn;
	
	this( long n )
	{
		ps.length = n;
		ps[] = -1;
		rs.length = n;
		rn = n;
	}
	
	long root( long i )
	{
		if( ps[ i ] < 0 ) return i;
		else              return ps[ i ] = root( ps[ i ] );
	}
	
	auto same( long i, long j )
	{
		return root( i ) == root( j );
	}
	
	auto unite( long i, long j )
	{
		i = root( i );
		j = root( j );
		if( i == j ) return;
		if( rs[ i ] < rs[ j ] )
		{
			ps[ j ] += ps[ i ];
			ps[ i ] = j;
		}
		else
		{
			ps[ i ] += ps[ j ];
			ps[ j ] = i;
			if( rs[ i ] == rs[ j ] ) rs[ i ]++;
		}
		rn--;
	}
	
	auto weight( long i )
	{
		return -ps[ root( i ) ];
	}
	
	auto rootnum()
	{
		return rn;
	}
	
	auto toString()
	{
		return ps.to!( string );
	}
}
