#K36642. Taco Challenge

    ID: 25800 Type: Default 1000ms 256MiB

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

Output: 1 2 3

</p>

inputFormat

The input is given via standard input (stdin) and has the following format:

  1. The first line contains an integer N, the number of nodes in the tree.
  2. The next N-1 lines each contain three integers u v w, representing an edge between nodes u and v with weight w.
  3. The following line contains an integer Q, the number of queries.
  4. 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.

## sample
5
1 2 3
1 3 4
1 4 2
4 5 1
3
1
2
3
1

2 3

</p>