#P1803. qtree3-Spoj1487 Query on a tree III
qtree3-Spoj1487 Query on a tree III
PT07J - Query on a tree III
题面翻译
你被给定一棵带点权的 个点的有根树,点从 到 编号。
定义查询 :寻找以 为根的子树中的第 小点的编号(从小到大排序第 个点)。
保证没有两个相同的点权。
输入格式:第一行为整数 ,第二行为点权,接下来 行为树边,接下来一行为整数 ,下面 行为两个整数 ,代表查询 。
输出格式: 行,输出每次查询的结果。
题目描述
You are given a node-labeled rooted tree with n nodes.
Define the query (x, k): Find the node whose label is k-th largest in the subtree of the node x. Assume no two nodes have the same labels.
输入格式
The first line contains one integer n (1 <= n <= 10 ). The next line contains n integers l (0 <= l <= 10 ) which denotes the label of the i-th node.
Each line of the following n - 1 lines contains two integers u, v. They denote there is an edge between node u and node v. Node 1 is the root of the tree.
The next line contains one integer m (1 <= m <= 10 ) which denotes the number of the queries. Each line of the next m contains two integers x, k. (k <= the total node number in the subtree of x)
输出格式
For each query (x, k), output the index of the node whose label is the k-th largest in the subtree of the node x.
样例 #1
样例输入 #1
5
1 3 5 2 7
1 2
2 3
1 4
3 5
4
2 3
4 1
3 2
3 2
样例输出 #1
5
4
5
5