#abc239e. E - Subtree K-th Max
E - Subtree K-th Max
Score : points
问题描述
我们有一棵包含 个顶点的有根树。顶点编号为 到 ,其中顶点 是树的根节点。
第 条边连接顶点 和 。
顶点 上写有一个整数 。
你将获得 个查询请求。对于第 个查询,给定一对整数 ,回答以下问题:
- 问题:在以顶点 为根的子树中,找出所写整数中的第 大值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a rooted tree with vertices. The vertices are numbered through , and the root is Vertex .
The -th edge connects Vertices and .
Vertex has an integer written on it.
You are given queries. For the -th query, given a pair of integers , answer the following question.
- Question: among the integers written on the vertices in the subtree rooted at Vertex , find the -th largest value.
Constraints
- The given graph is a tree.
- The subtree rooted at Vertex has or more vertices.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the response to the -th query.
Sample Input 1
5 2
1 2 3 4 5
1 4
2 1
2 5
3 2
1 2
2 1
Sample Output 1
4
5
The tree given in this input is shown below.
For the -st query, the vertices in the subtree rooted at Vertex are Vertices , and , so print the -nd largest value of the numbers written on these vertices, .
For the -nd query, the vertices in the subtree rooted at Vertex are Vertices , and , so print the -st largest value of the numbers written on these vertices, .
Sample Input 2
6 2
10 10 10 9 8 8
1 4
2 1
2 5
3 2
6 4
1 4
2 2
Sample Output 2
9
10
Sample Input 3
4 4
1 10 100 1000
1 2
2 3
3 4
1 4
2 3
3 2
4 1
Sample Output 3
1
10
100
1000
update @ 2024/3/10 10:19:15