#include <bits/stdc++.h>
using namespace std;
const int N = 100100, L = 40;
long long w[N], sum[N][L], to[N][L], MN[N][L], k;
int n, f[N];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> f[i];
  for (int i = 0; i < n; i++) cin >> w[i];
  for (int i = 0; i < n; i++) {
    sum[i][0] = w[i];
    to[i][0] = f[i];
    MN[i][0] = w[i];
  }
  for (int lg = 1; lg < L; lg++) {
    for (int i = 0; i < n; i++) {
      sum[i][lg] = sum[i][lg - 1] + sum[to[i][lg - 1]][lg - 1];
      to[i][lg] = to[to[i][lg - 1]][lg - 1];
      MN[i][lg] = min(MN[i][lg - 1], MN[to[i][lg - 1]][lg - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    long long Sum = 0, mn = 1ll << 62;
    int kk = k, from = i;
    for (int j = 0; j < L; j++)
      if (k & (1ll << j)) {
        Sum += sum[from][j];
        mn = min(mn, MN[from][j]);
        from = to[from][j];
      }
    cout << Sum << " " << mn << endl;
  }
  return 0;
}
