#include <bits/stdc++.h>
using namespace std;
const int LG = 40;
const int N = 1e5 + 5;
const int W = 1e8 + 5;
int n, par[N][LG], mn[N][LG];
long long k, sum[N][LG];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> par[i][0];
  }
  for (int i = 0; i < n; i++) {
    cin >> sum[i][0];
    mn[i][0] = sum[i][0];
  }
  for (int j = 1; 1LL << j <= k; j++) {
    for (int i = 0; i < n; i++) {
      par[i][j] = par[par[i][j - 1]][j - 1];
      sum[i][j] = sum[i][j - 1] + sum[par[i][j - 1]][j - 1];
      mn[i][j] = min(mn[i][j - 1], mn[par[i][j - 1]][j - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    int v = i, m = W;
    long long s = 0, x = k;
    int j = 0;
    while (x) {
      if (x & 1) {
        s += sum[v][j];
        m = min(m, mn[v][j]);
        v = par[v][j];
      }
      j++;
      x >>= 1;
    }
    cout << s << ' ' << m << '\n';
  }
  return 0;
}
