constint N = 2e5 + 10, M = N << 2; #define int long long int h[N], e[M], ne[M], idx; int n, m; int w[N]; voidadd(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
voiddfs(int u, int f) { for(int i = h[u]; ~i; i = ne[i]) { int j = e[i]; if(j == f) continue; w[j] += w[u]; dfs(j, u); } }
signedmain(int argc, charconst *argv[]) { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m; memset(h, -1, sizeof h); for(int i = 1; i < n; i++) { int x, y; cin >> x >> y; add(x, y); add(y, x); } for(int i = 0; i < m; i++) { int x, y; cin >> x >> y; w[x] += y; } dfs(1, -1); for(int i = 1; i <= n; i++) cout << w[i] << " \n"[i == n]; return0; }