#K36642. Taco Challenge
Taco Challenge
Taco Challenge
You are given a tree with N nodes (numbered from 1 to N) and N-1 weighted edges. The tree is provided by its edge list, where each edge connects two nodes and has an integer weight.
Your task is to process Q queries. For each query, given an integer k, you need to determine the following:
- If k is less than the total number of edges, output the k-th smallest edge weight (when the edges are sorted in ascending order by weight).
- If k is greater than or equal to the number of edges, output the largest edge weight.
Note that the input represents a valid tree; however, the tree structure is only used to obtain the edge weights, and your answer depends solely on the sorted order of these weights.
Example:
Input: 5 1 2 3 1 3 4 1 4 2 4 5 1 3 1 2 3</p>Output: 1 2 3
inputFormat
The input is given via standard input (stdin) and has the following format:
- The first line contains an integer N, the number of nodes in the tree.
- The next N-1 lines each contain three integers u v w, representing an edge between nodes u and v with weight w.
- The following line contains an integer Q, the number of queries.
- The next Q lines each contain one integer k, representing a query.
outputFormat
For each query, output the corresponding answer on a new line using standard output (stdout). Each answer is an integer.
## sample5
1 2 3
1 3 4
1 4 2
4 5 1
3
1
2
3
1
2
3
</p>