PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000060. Vasya và cây (Vasya and a Tree)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

3 lộ trình

Vasya và cây (Vasya and a Tree)

Vasya and a Tree

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Vasya has a tree of nn vertices rooted at 11. Initially every vertex holds value 00. Each of the mm operations (v,d,x)(v,d,x) adds xx to every vertex uu in the rooted subtree of vv whose distance from vv is at most dd edges. The vertex vv itself is included. All modifications accumulate and the tree structure does not change. Report the final value of every vertex.

Input

First line: nn. Next n−1n-1 lines: undirected edges u vu\ v. Next line: mm. The next mm lines contain v d xv\ d\ x.

Output

Print nn integers in order of vertices 11 through nn.

Subtasks

General constraints: 1≤n≤3⋅1051\le n\le 3\cdot10^5; 1≤m≤3⋅1051\le m\le 3\cdot10^5; 0≤d≤1090\le d\le10^9; 1≤x≤1091\le x\le 10^9; cây vô hướng, liên thông.

  • Subtask 1 (20 points): 1≤n≤401\le n\le 40; 1≤q≤501\le q\le 50.

  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000; 1≤q≤10001\le q\le 1000.

  • Subtask 3 (50 points): 1≤n≤3000001\le n\le 300000; 1≤q≤3000001\le q\le 300000.

Examples

Input

5
1 2
1 3
2 4
2 5
3
1 1 1
2 0 10
4 10 100

Output

1 11 1 100 0

Explanation

Vertex 11 gains 11, vertex 22 gains 1+10=111+10=11, vertex 33 gains 11, vertex 44 gains 100100, and vertex 55 is unaffected.