#include <bits/stdc++.h>
typedef int iarrN[100003][35];
struct IO {
  template <typename T>
  inline IO operator>>(T &n) {
    n = 0;
    char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    while (c >= '0' && c <= '9')
      n = (n << 3) + (n << 1) + (c ^ 48), c = getchar();
    return *this;
  }
} cin;
constexpr int MX = 33, inf = 0x3f3f3f3f;
int N, son[100003][35], mnw[100003][35];
long long K, sw[100003][35];
void init() {
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) cin >> son[i][0], ++son[i][0];
  for (int i = 1; i <= N; ++i) cin >> mnw[i][0], sw[i][0] = mnw[i][0];
  for (int j = 1; j <= MX; ++j)
    for (int i = 1; i <= N; ++i) {
      son[i][j] = son[son[i][j - 1]][j - 1];
      sw[i][j] = sw[i][j - 1] + sw[son[i][j - 1]][j - 1];
      mnw[i][j] = std::min(mnw[i][j - 1], mnw[son[i][j - 1]][j - 1]);
    }
}
inline void query(int u) {
  int ansmn = inf;
  long long k = K, anss = 0;
  for (int i = MX; i >= 0; --i)
    if (k >= (1ll << i)) {
      k -= 1ll << i;
      anss += sw[u][i];
      ansmn = std::min(ansmn, mnw[u][i]);
      u = son[u][i];
    }
  printf("%I64d %d\n", anss, ansmn);
}
int main() {
  init();
  for (int i = 1; i <= N; ++i) query(i);
  return 0;
}
