Text from the official booklet. Refer to the PDF for original mathematical notation, formatting, and linked input files. Printed samples and inputs are reproduced as published.
There are N attractions in a huge amusement park, numbered 1 to N . They are con-
nected by N − 1 walkways, and these walkways form a tree (so there is exactly one
simple path between any two attractions). Each walkway has a thrill rating T .
You will receive Q questions. Each question gives you a value X. For that question,
you will only walk on walkways where: thrill rating ≥ X
Starting from attraction 1, you must find:
How many attractions can be reached using only walkways with a thrill rating of at
least X?
You must output this number for every query.
Input Format:
N Q
u1 v1 T1
u2 v2 T2
...
u_{N-1} v_{N-1} T_{N-1}
X1
X2
...
XQ
• N = number of attractions
• Q = number of queries
• Each walkway connects ui and vi and has thrill rating Ti
• Each query Xi is the minimum thrill you allow for walking
Output Format: For each query Xi, print the number of attractions reachable from
attraction 1 using only walkways where: T ≥ Xi
Constraints:
• 1 ≤ N, Q≤ 200, 000
• 1 ≤ Ti, Xi ≤ 109
Example Input:
5 4
1 2 5
2 3 2
2 4 8
4 5 6
1
3
5
7
Example Output:
5
4
4
1
Question Input File:
• Input: https://shorturl.at/1NHcP