#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long k;
  scanf("%d %I64d", &n, &k);
  int f[n];
  long long w[n];
  for (int i = 0; i < n; i++) scanf("%d", &f[i]);
  for (int i = 0; i < n; i++) scanf("%I64d", &w[i]);
  int anc[n][34];
  long long sum[n][34], mn[n][34];
  for (int i = 0; i < n; i++) {
    anc[i][0] = f[i];
    sum[i][0] = w[i];
    mn[i][0] = w[i];
  }
  for (int i = 1; i < 34; i++) {
    for (int j = 0; j < n; j++) {
      anc[j][i] = anc[anc[j][i - 1]][i - 1];
      sum[j][i] = sum[anc[j][i - 1]][i - 1] + sum[j][i - 1];
      mn[j][i] = min(mn[anc[j][i - 1]][i - 1], mn[j][i - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    int ank = i;
    long long csum = 0, cmn = 1001001001;
    for (long long j = 34; j >= 0; j--) {
      if (k & (1ll << j)) {
        csum += sum[ank][j];
        cmn = min(cmn, mn[ank][j]);
        ank = anc[ank][j];
      }
    }
    printf("%I64d %I64d\n", csum, cmn);
  }
  return 0;
}
