#include <iostream>
#include <vector>
using namespace std;
#define MAXN 100000
vector<int> children[MAXN];
int N, M;
int W[MAXN];
int ans[MAXN];
void dfs(int cur, int sum) {
for (auto it = children[cur].begin(); it != children[cur].end(); it++) {
ans[*it] = sum + W[*it];
dfs(*it, sum + W[*it]);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
for (int i = 0; i < N; i++) {
int idx;
cin >> idx;
if (idx == -1) continue;
idx--;
children[idx].push_back(i);
}
while (M--) {
int idx, w;
cin >> idx >> w;
idx--;
W[idx] += w;
}
dfs(0, 0);
for (int i = 0; i < N; i++) {
cout << ans[i] << " ";
}
return 0;
}