← November 2025 questions

NOVEMBER 2025 / ADVANCED / QUESTION 5

Question 5

Archived question

Try the question in your own editor, then check your output below.

THE QUESTION

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

PRACTICE CHECK

Try your answer.

The linked final-input download could not be retrieved (checked 28 October 2026). This checks the complete published sample, not the unavailable final input.

Run your program in your own editor, then paste its output below. This checks the stated output or checkpoint; it does not assess your full program. Practice attempts do not affect competition scores.

Use the published five-attraction example, with thresholds 1, 3, 5 and 7. Enter four counts in that order.

Reveal worked answer

Your output

5
4
4
1

For each threshold traverse only qualifying edges from node 1. Include node 1 itself in the count.

Source: Girls in Code SEA 2025 Fall Competition, 29 November 2025. Booklet created by Emily Xu and the GIC question authors. Shared for non-commercial educational use with attribution, as permitted in the booklet.