#include <bits/stdc++.h>
using namespace std;
int mmin[100010][50];
long long sum[100010][50];
int son[100010][50];
long long poww[50];
void pre() {
  poww[0] = 1;
  for (int i = 1; i <= 40; i++) poww[i] = poww[i - 1] << 1;
}
long long n, k;
long long SUM;
int MMIN;
void solve(int h, long long k) {
  SUM = 0, MMIN = 0;
  MMIN = 2e9;
  for (int i = 40; i >= 0; i--)
    if (poww[i] <= k)
      MMIN = min(MMIN, mmin[h][i]), SUM += sum[h][i], k -= poww[i],
      h = son[h][i];
}
long long read() {
  long long sum = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
  return sum;
}
int main() {
  pre();
  n = read(), k = read();
  for (int i = 0; i < n; i++) son[i][0] = read();
  for (int i = 0; i < n; i++) mmin[i][0] = sum[i][0] = read();
  for (int i = 1; i <= 40; i++)
    for (int j = 0; j < n; j++) {
      son[j][i] = son[son[j][i - 1]][i - 1];
      sum[j][i] = sum[son[j][i - 1]][i - 1] + sum[j][i - 1];
      mmin[j][i] = min(mmin[j][i - 1], mmin[son[j][i - 1]][i - 1]);
    }
  for (int i = 0; i < n; i++) {
    solve(i, k);
    cout << SUM << " " << MMIN << '\n';
  }
  return 0;
}
