#LCA0000047. Trò chơi nóng và lạnh (Hot and Cold)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trò chơi nóng và lạnh (Hot and Cold)
Hot and Cold
Source: DMOJ
Version: Phuoc Hung OJ Extended
Problem Statement
A game takes place on an unweighted undirected tree with vertices. There are independent seekers.
In game , its seeker visits every vertex on the unique path from to , including both endpoints. The target for that game is . At each visited vertex , the game leader announces the distance, in edges, from to .
For each vertex, calculate the sum of all distances announced there throughout the games. An unvisited vertex has sum .
Input
- The first line contains .
- The next lines each contain an undirected edge .
- Each of the next lines contains : start, end and target of one game.
Output
Print integers, in vertex order , representing the sum of distances announced at each vertex.
Subtasks
General constraints: ; . Tổng có thể vượt giới hạn số nguyên 32-bit.
-
Subtask 1 (20 points): ; .
-
Subtask 2 (30 points): ; .
-
Subtask 3 (50 points): ; .
Examples
Input
5 3
1 2
2 3
2 4
1 5
3 5 1
5 4 1
2 4 1
Output
0 3 2 4 2
Explanation
Game 1 visits with target and contributes at those vertices. Game 2 visits and adds . Game 3 visits and adds there. The totals for vertices to are .