显示代码纯文本
#include<iostream>
#include<cstdio>
using namespace std;
int n,k,t[100010],w[100010],mi;
long long s;
void find(int x,int b)
{
if(b==k)
{
cout<<s<<' '<<mi<<endl;
return;
}
if(t[x]==x&&b==0)
{
cout<<w[x]*k<<' '<<w[x]<<endl;
return;
}
s+=w[x];
if(w[x]<mi)
{
mi=w[x];
}
b++;
find(t[x],b);
}
int main()
{
freopen("pathsjump.in","r",stdin);
freopen("pathsjump.out","w",stdout);
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>t[i];
}
for(int i=1;i<=n;i++)
{
cin>>w[i];
}
for(int i=1;i<=n;i++)
{
s=0;
mi=0x3f3f3f3f;
find(i,0);
}
return 0;
}