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
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 vertices, rooted at vertex . Initially each vertex has value .
There are operations. An operation adds to every vertex in the subtree rooted at , including . Operations accumulate when their subtrees overlap.
Print the final value at each vertex after all operations.
Input
- The first line contains .
- Each of the next lines contains the endpoints of an undirected edge.
- Each of the last lines contains an operation .
Output
Print space-separated values in vertex order through .
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
4 3
1 2
2 3
2 4
2 10
1 100
3 1
Output
100 110 111 110
Explanation
Vertex adds to its subtree, the entire tree receives , and the subtree of vertex receives another . The final values are .