#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int child[N], w[N];
long long dp[N][35][3], ans[N][2];
void pre(int n) {
  for (int i = 0; i < n; i++) {
    dp[i][0][0] = w[i];
    dp[i][0][2] = w[i];
    dp[i][0][1] = child[i];
  }
  for (int j = 1; j < 35; j++) {
    for (int i = 0; i < n; i++) {
      dp[i][j][1] = dp[dp[i][j - 1][1]][j - 1][1];
      dp[i][j][0] = dp[i][j - 1][0] + dp[dp[i][j - 1][1]][j - 1][0];
      dp[i][j][2] = min(dp[i][j - 1][2], dp[dp[i][j - 1][1]][j - 1][2]);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> child[i];
  for (int i = 0; i < n; i++) cin >> w[i];
  pre(n);
  int pt;
  for (int i = 0; i < n; i++) {
    pt = i;
    ans[i][1] = 1000000007ULL;
    for (long long j = 0; (1LL << j) <= k; j++) {
      if ((1LL << j) & k) {
        ans[i][0] += dp[pt][j][0];
        ans[i][1] = min(ans[i][1], dp[pt][j][2]);
        pt = dp[pt][j][1];
      }
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i][0] << " " << ans[i][1] << "\n";
  return 0;
}
