#include <bits/stdc++.h>
using namespace std;
int n, k;
int viz[100002], dad[100002], ans[100002], mx[100002];
vector<int> v[100002];
void dfs(int nod) {
  viz[nod] = 1;
  if (!dad[nod]) {
    ans[nod] = 1 + min(k, nod - 1) + min(k, n - (nod + 1) + 1);
    mx[nod] = min(nod + k, n);
  } else {
    if (mx[dad[nod]] == n)
      ans[nod] = ans[dad[nod]];
    else
      ans[nod] =
          ans[dad[nod]] + min(n, (nod + k)) - max(mx[dad[nod]], nod - k - 1);
    mx[nod] = min(nod + k, n);
  }
  for (int i = 0; i < v[nod].size(); ++i) {
    int vecin = v[nod][i];
    dfs(vecin);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    int tt;
    cin >> tt;
    if (tt) v[tt].push_back(i);
    dad[i] = tt;
  }
  for (int i = 1; i <= n; ++i)
    if (!viz[i]) dfs(i);
  for (int i = 1; i <= n; ++i) cout << ans[i] << " ";
  return 0;
}
