#LCA0000094. Loại hàng cứu trợ phổ biến nhất (Rainy Tails)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Loại hàng cứu trợ phổ biến nhất (Rainy Tails)
Rainy Tails
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
A village contains houses connected by undirected roads forming a tree. Each of relief-distribution events delivers one bag of type to every house on the unique path from to , including both endpoints.
For each house, output the type ID with the highest total number of bags. If several types tie for the maximum frequency, choose the smallest type ID. Output 0 for houses that received no bags.
Input
The first line contains . Next are undirected edges , followed by events .
Output
Print lines. Line is the most frequent type ID in house , or 0 if the house has no bags.
Subtasks
-
Subtask 1 (20 points): ; ; ; ; edges form a tree.
-
Subtask 2 (30 points): ; ; ; ; edges form a tree.
-
Subtask 3 (50 points): ; ; ; ; edges form a tree.
Examples
Input
5 3
1 2
1 3
3 4
3 5
2 4 7
2 5 3
4 5 7
Output
3
3
7
7
3
Explanation
Event 1 delivers type along , event 2 delivers type along , and event 3 delivers type along . Houses tie between types and choose . Houses choose type . House also ties and chooses .