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

#LCA0000002. Lan truyền điểm trên cây (Ki)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Lan truyền điểm trên cây (Ki)

Ki

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an undirected tree with nn vertices, rooted at vertex 11. Initially each vertex has value 00.

There are qq operations. An operation (pi,xi)(p_i,x_i) adds xix_i to every vertex in the subtree rooted at pip_i, including pip_i. Operations accumulate when their subtrees overlap.

Print the final value at each vertex after all operations.

Input

  • The first line contains n,qn,q.
  • Each of the next n−1n-1 lines contains the endpoints ai,bia_i,b_i of an undirected edge.
  • Each of the last qq lines contains an operation pi,xip_i,x_i.

Output

Print nn space-separated values in vertex order 11 through nn.

Subtasks

  • Subtask 1 (20 points): n≤30n\le30; q≤60q\le60; 2≤n≤2⋅1052\le n\le2\cdot10^5; 1≤q≤2⋅1051\le q\le2\cdot10^5; 1≤xi≤1041\le x_i\le10^4.
  • Subtask 2 (30 points): n≤1000n\le1000; q≤3000q\le3000; 2≤n≤2⋅1052\le n\le2\cdot10^5; 1≤q≤2⋅1051\le q\le2\cdot10^5; 1≤xi≤1041\le x_i\le10^4.
  • Subtask 3 (50 points): 2≤n≤2⋅1052\le n\le2\cdot10^5; 1≤q≤2⋅1051\le q\le2\cdot10^5; 1≤xi≤1041\le x_i\le10^4.

Examples

Input

4 3
1 2
2 3
2 4
2 10
1 100
3 1

Output

100 110 111 110

Explanation

Vertex 22 adds 1010 to its subtree, the entire tree receives 100100, and the subtree of vertex 33 receives another 11. The final values are 100,110,111,110100,110,111,110.