#include <bits/stdc++.h>
using namespace std;
int n, fa[100010][40], mn[100010][40];
long long k, s[100010][40];
void work(int x) {
  long long si = 0;
  int mi = 1e9;
  for (int i = 35; i >= 0; i--) {
    if ((1LL << i) & k) {
      si += s[x][i];
      mi = min(mi, mn[x][i]);
      x = fa[x][i];
    }
  }
  printf("%I64d %d\n", si, mi);
}
int main() {
  scanf("%d%I64d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &fa[i][0]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &mn[i][0]);
    s[i][0] = mn[i][0];
  }
  for (int i = 1; i <= 35; i++) {
    for (int j = 0; j < n; j++) {
      fa[j][i] = fa[fa[j][i - 1]][i - 1];
      s[j][i] = s[j][i - 1] + s[fa[j][i - 1]][i - 1];
      mn[j][i] = min(mn[j][i - 1], mn[fa[j][i - 1]][i - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    work(i);
  }
  return 0;
}
