#include <bits/stdc++.h>
using namespace std;
long long f[100001][50], sum, w[100001][50], s[100001][50];
int main() {
  long long i, j, k, x, m, n;
  cin >> n >> k;
  for (i = 0; i <= n - 1; i++) cin >> f[i][0];
  for (i = 0; i <= n - 1; i++) {
    cin >> w[i][0];
    s[i][0] = w[i][0];
  }
  for (j = 1; j <= 45; j++)
    for (i = 0; i <= n - 1; i++) {
      f[i][j] = f[f[i][j - 1]][j - 1];
      w[i][j] = min(w[i][j - 1], w[f[i][j - 1]][j - 1]);
      s[i][j] = s[i][j - 1] + s[f[i][j - 1]][j - 1];
    }
  for (i = 0; i <= n - 1; i++) {
    m = w[i][0];
    x = i;
    sum = 0;
    for (j = 0; j <= 45; j++) {
      if (k & 1LL << j) {
        sum += s[x][j];
        m = min(m, w[x][j]);
        x = f[x][j];
      }
    }
    cout << sum << " " << m << endl;
  }
  return 0;
}
