#include <bits/stdc++.h>
using namespace std;
long long minn[100010][40], f[100010][40], son[100010][40], n, k;
void solve(int x) {
  long long ans = 0, minnn = 1e18;
  long long s = k;
  for (int i = 35; i >= 0; i--) {
    if ((1ll << (1ll * i)) <= s) {
      ans += f[x][i];
      minnn = min(minnn, minn[x][i]);
      x = son[x][i];
      s -= (1ll << (1ll * i));
    }
  }
  cout << ans << " " << minnn << endl;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> son[i][0];
  for (int i = 0; i < n; i++) {
    cin >> f[i][0];
    minn[i][0] = f[i][0];
  }
  for (int i = 1; i <= 35; i++)
    for (int j = 0; j < n; j++) {
      son[j][i] = son[son[j][i - 1]][i - 1];
      f[j][i] = f[j][i - 1] + f[son[j][i - 1]][i - 1];
      minn[j][i] = min(minn[j][i - 1], minn[son[j][i - 1]][i - 1]);
    }
  for (int i = 0; i < n; i++) solve(i);
  return 0;
}
