#include <bits/stdc++.h>
using namespace std;
const int N(100005);
const long long inf((long long)1 << 60);
int n;
long long k, minn[35], ver[N][35], edge1[N][35], edge2[N][35];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i(1); i <= n; ++i) cin >> ver[i][0], ++ver[i][0];
  for (int i(1); i <= n; ++i) {
    cin >> edge1[i][0];
    edge2[i][0] = edge1[i][0];
  }
  for (int i(1); i <= 34; ++i) {
    for (int j(1); j <= n; ++j) {
      ver[j][i] = ver[ver[j][i - 1]][i - 1];
      edge1[j][i] = edge1[ver[j][i - 1]][i - 1] + edge1[j][i - 1];
      edge2[j][i] = ((edge2[ver[j][i - 1]][i - 1]) < (edge2[j][i - 1])
                         ? (edge2[ver[j][i - 1]][i - 1])
                         : (edge2[j][i - 1]));
    }
  }
  minn[0] = 1;
  for (int i(1); i <= 34; ++i) minn[i] = minn[i - 1] << 1;
  for (int i(1); i <= n; ++i) {
    int now(i);
    long long step(k), ans1(0), ans2(inf);
    for (int i(34); i >= 0; --i) {
      if (step >= minn[i]) {
        step -= minn[i];
        ans1 += edge1[now][i];
        ans2 = ((ans2) < (edge2[now][i]) ? (ans2) : (edge2[now][i]));
        now = ver[now][i];
      }
    }
    cout << ans1 << " " << ans2 << "\n";
  }
  return 0;
}
