#include <bits/stdc++.h>
using namespace std;
int N;
long long K;
int to[100005];
long long W[100005];
int pa[100005][35];
long long st1[100005][35], st2[100005][35];
long long ans1[100005], ans2[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  for (int i = 0; i <= N - 1; i++) cin >> to[i];
  for (int i = 0; i <= N - 1; i++) {
    cin >> W[i];
    pa[i][0] = to[i];
    st1[i][0] = W[i];
    st2[i][0] = W[i];
  }
  long long ln = 2;
  int lg = 1;
  int mxlg = 0;
  while (ln <= K) {
    mxlg++;
    for (int i = 0; i <= N - 1; i++) {
      pa[i][lg] = pa[pa[i][lg - 1]][lg - 1];
      st1[i][lg] = st1[i][lg - 1] + st1[pa[i][lg - 1]][lg - 1];
      st2[i][lg] = min(st2[i][lg - 1], st2[pa[i][lg - 1]][lg - 1]);
    }
    ln <<= 1;
    lg++;
  }
  for (int i = 0; i <= N - 1; i++) {
    ans1[i] = 0;
    ans2[i] = (1LL << 60);
    int u = i;
    for (int b = mxlg; b >= 0; b--) {
      if (K & (1LL << b)) {
        ans1[i] += st1[u][b];
        ans2[i] = min(ans2[i], st2[u][b]);
        u = pa[u][b];
      }
    }
  }
  for (int i = 0; i <= N - 1; i++) {
    cout << ans1[i] << ' ' << ans2[i] << '\n';
  }
  return 0;
}
