您當前處於相容模式。某些功能在此模式下不可用。我們強烈建議在現代瀏覽器上切換為標準模式以獲得更好的體驗。 標準模式 隱藏

#include<bits/stdc++.h>
using namespace std;
long long n, k, nxt[5005], c[5005], maxn=LLONG_MIN;
long long main(){
	freopen("chess.in", "r", stdin);
	freopen("chess.out", "w", stdout);
	cin>>n>>k;
	for(long long i = 1; i <= n; i++) cin>>nxt[i];
	for(long long i = 1; i <= n; i++) cin>>c[i];
	for(long long i = 1; i <= n; i++)
		long long cur=i, cnt=0;
		for(long long j = 0; j <= k; j++)
			cnt += c[cur];
			if(cnt>maxn) maxn=cnt;
			cur = nxt[cur];
		
	
	cout<<maxn;
	return 1;
}

0 條評論

目前還沒有評論...

資訊

ID
2337
時間
ms
記憶體
MiB
難度
9
標籤
(無)
遞交數
47
已通過
4
上傳者