#P4556. 【模板】线段树合并 / [Vani 有约会] 雨天的尾巴
【模板】线段树合并 / [Vani 有约会] 雨天的尾巴
Description
There are houses in the village, forming a tree. Relief rations are distributed times. Each time, two houses are chosen. For every house on the path from to (including and ), one bag of type relief rations is given.
After all distributions are finished, Shenhuili wants to know, for each house, which type of relief rations is stored the most.
Input Format
The first line contains two positive integers and .
Lines through each contain two integers , indicating that there is an edge between houses and .
Lines through each contain three integers , indicating that in one distribution, every house on the path from to receives one bag of type relief rations.
Output Format
Output lines. The integer on the -th line is the type of relief rations that appears most in house . If multiple types are tied for the maximum, output the smallest type id.
If a house has no relief rations, output 0.
5 3
1 2
3 1
3 4
5 3
2 3 3
1 5 2
3 3 3
2
3
3
0
2
Hint
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号