#include <bits/stdc++.h>
using namespace std;
int fa[100010][35], Min[100010][35];
long long w[100010][35], n, k;
long long Sum(int x, long long p) {
  if (p == 0) return 0;
  int t = 0;
  long long sum = 1;
  while (sum <= p) {
    t++;
    sum <<= 1;
  }
  t--;
  sum >>= 1;
  return w[x][t] + Sum(fa[x][t], p - sum);
}
int Minn(int x, long long p) {
  if (p == 0) return 1e9;
  int t = 0;
  long long sum = 1;
  while (sum <= p) {
    t++;
    sum <<= 1;
  }
  t--;
  sum >>= 1;
  return min(Min[x][t], Minn(fa[x][t], p - sum));
}
int main() {
  scanf("%I64d%I64d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &fa[i][0]);
  for (int i = 0; i < n; i++) scanf("%I64d", &w[i][0]), Min[i][0] = w[i][0];
  for (int i = 1; i <= 34; i++)
    for (int j = 0; j < n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];
  for (int i = 1; i <= 34; i++)
    for (int j = 0; j < n; j++) w[j][i] = w[j][i - 1] + w[fa[j][i - 1]][i - 1];
  for (int i = 1; i <= 34; i++)
    for (int j = 0; j < n; j++)
      Min[j][i] = min(Min[j][i - 1], Min[fa[j][i - 1]][i - 1]);
  for (int i = 0; i < n; i++) printf("%I64d %d\n", Sum(i, k), Minn(i, k));
}
