#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, dp[N][45];
long long minn[N][45], sum[N][45];
long long k;
void solve(int xx) {
  int x = xx;
  long long ret = 0;
  for (int i = 0; i <= 40; ++i) {
    if ((k >> i) & 1) {
      ret += sum[x][i];
      x = dp[x][i];
    }
  }
  printf("%lld ", ret);
  ret = 1000000000000;
  x = xx;
  for (int i = 0; i <= 40; ++i) {
    if ((k >> i) & 1) {
      ret = min(ret, minn[x][i]);
      x = dp[x][i];
    }
  }
  printf("%lld\n", ret);
}
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &dp[i][0]);
    ++dp[i][0];
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &sum[i][0]);
    minn[i][0] = sum[i][0];
  }
  for (int j = 1; j <= 40; ++j) {
    for (int i = 1; i <= n; ++i) {
      dp[i][j] = dp[dp[i][j - 1]][j - 1];
    }
  }
  for (int j = 1; j <= 40; ++j) {
    for (int i = 1; i <= n; ++i) {
      sum[i][j] = sum[i][j - 1] + sum[dp[i][j - 1]][j - 1];
    }
  }
  for (int j = 1; j <= 40; ++j) {
    for (int i = 1; i <= n; ++i) {
      minn[i][j] = min(minn[i][j - 1], minn[dp[i][j - 1]][j - 1]);
    }
  }
  for (int i = 1; i <= n; ++i) solve(i);
  return 0;
}
