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 );

	assert( [ "3 1", "2 3 1", "-1 -2 -3" ].solve == -1 );		// 追加ケース
}



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 lls = new long[ n ];
	auto lts = new long[ n ];
	{
		auto gs = new long[ n ];
		gs[] = -1;
		foreach( s, ref ll, ref lt, ref g; lockstep( lls, lts, gs ) )
		{
			if( g < 0 )
			{
				for( auto p = ps[ s ]; gs[ p ] < 0; p = ps[ p ] )
				{
					ll++;
					lt += cs[ p ];
					gs[ p ] = s;
				}
			}
			else
			{
				lt = lts[ g ];
				ll = lls[ g ];
			}
		}
	}
	
	// スコアの最大値を計算
	auto ans = long.min;
	foreach( s, ll, lt; lockstep( lls, lts ) )
	{
		auto lc = k / ll;
		auto lr = k % ll;
		
		if( 0 < lc ) ans = max( ans, lt * lc );
		for( auto i = 1L, p = ps[ s ], t = 0L; i <= k && p != s; i++, p = ps[ p ] )
		{
			t += cs[ p ];
			ans = max( ans, t, t + lt * ( lc - ( lr < i ) ) );
		}
	}
	return ans;
}
