#LCA0000060. Vasya và cây (Vasya and a Tree)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 vertices rooted at . Initially every vertex holds value . Each of the operations adds to every vertex in the rooted subtree of whose distance from is at most edges. The vertex itself is included. All modifications accumulate and the tree structure does not change. Report the final value of every vertex.
Input
First line: . Next lines: undirected edges . Next line: . The next lines contain .
Output
Print integers in order of vertices through .
Subtasks
General constraints: ; ; ; ; cây vô hướng, liên thông.
-
Subtask 1 (20 points): ; .
-
Subtask 2 (30 points): ; .
-
Subtask 3 (50 points): ; .
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 gains , vertex gains , vertex gains , vertex gains , and vertex is unaffected.