#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  register int ans = 0, flag = 1;
  register char c = getchar();
  for (; c > '9' || c < '0'; c = getchar())
    if (c == '-') flag = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) ans = ans * 10 - '0' + c;
  return ans * flag;
}
inline long long rdll() {
  register long long ans = 0, flag = 1;
  register char c = getchar();
  for (; c > '9' || c < '0'; c = getchar())
    if (c == '-') flag = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) ans = ans * 10 - '0' + c;
  return ans * flag;
}
const int MAXN = 1e5 + 10;
const int MAXLOGN = 50;
long long LOGN;
int to[MAXN], val[MAXN];
long long pt[MAXLOGN];
int n;
long long k;
int f[MAXN][MAXLOGN + 1];
long long m[MAXN][MAXLOGN + 1];
long long s[MAXN][MAXLOGN + 1];
int main() {
  n = rd();
  k = rdll();
  LOGN = 35;
  for (register int i = 1; i <= n; ++i) {
    to[i] = rd() + 1;
    f[i][0] = to[i];
  }
  for (register int i = 1; i <= n; ++i) {
    val[i] = rd();
    m[i][0] = val[i];
    s[i][0] = val[i];
  }
  pt[0] = 1;
  for (register int j = 1; j <= LOGN; ++j) {
    pt[j] = pt[j - 1] * 2;
    for (register int i = 1; i <= n; ++i) {
      f[i][j] = f[f[i][j - 1]][j - 1];
      m[i][j] = min(m[f[i][j - 1]][j - 1], m[i][j - 1]);
      s[i][j] = s[f[i][j - 1]][j - 1] + s[i][j - 1];
    }
  }
  for (register int i = 1; i <= n; ++i) {
    long long t = k;
    long long x = i;
    long long ans = INT_MAX;
    long long sum = 0;
    for (register int j = LOGN; j >= 0; --j) {
      if (pt[j] <= t) {
        t -= pt[j];
        sum += s[x][j];
        ans = min(ans, m[x][j]);
        x = f[x][j];
      }
    }
    printf("%lld %lld\n", sum, ans);
  }
  return 0;
}
