| 比赛 | 2025.3.29 | 评测结果 | WWWTTTTTTT |
|---|---|---|---|
| 题目名称 | Analysis of Pathes in Functional Graph | 最终得分 | 0 |
| 用户昵称 | 徐诗畅 | 运行时间 | 14.476 s |
| 代码语言 | C++ | 内存使用 | 4.78 MiB |
| 提交时间 | 2025-03-29 11:52:19 | ||
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int n,k,v[N],val[N];
signed main(){
freopen("pathsjump.in","r",stdin);
freopen("pathsjump.out","w",stdout);
scanf("%lld%lld",&n,&k);
for(int i = 0;i<n;i++) scanf("%lld",&v[i]);
for(int i = 0;i<n;i++) scanf("%lld",&val[i]);
for(int i = 0;i<n;i++){
int sum=0,ans=0x3f3f3f3f,pos=i;
for(int j=0;j<k;j++){
sum+=val[pos];
if(val[pos]<ans) ans=val[pos];
pos=v[pos];
}
printf("%lld %lld\n",sum,ans);
}
return 0;
}