CF627D.Preorder Test

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For his computer science class, Jacob builds a model tree with sticks and balls containing nn nodes in the shape of a tree. Jacob has spent aia_{i} minutes building the ii -th ball in the tree.

Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough time to search his whole tree to determine this; Jacob knows that she will examine the first kk nodes in a DFS-order traversal of the tree. She will then assign Jacob a grade equal to the minimum aia_{i} she finds among those kk nodes.

Though Jacob does not have enough time to rebuild his model, he can choose the root node that his teacher starts from. Furthermore, he can rearrange the list of neighbors of each node in any order he likes. Help Jacob find the best grade he can get on this assignment.

A DFS-order traversal is an ordering of the nodes of a rooted tree, built by a recursive DFS-procedure initially called on the root of the tree. When called on a given node vv , the procedure does the following:

  1. Print vv .
  2. Traverse the list of neighbors of the node vv in order and iteratively call DFS-procedure on each one. Do not call DFS-procedure on node uu if you came to node vv directly from uu .

输入格式

The first line of the input contains two positive integers, nn and kk ( 2<=n<=2000002<=n<=200000 , 1<=k<=n1<=k<=n ) — the number of balls in Jacob's tree and the number of balls the teacher will inspect.

The second line contains nn integers, aia_{i} ( 1<=ai<=10000001<=a_{i}<=1000000 ), the time Jacob used to build the ii -th ball.

Each of the next n1n-1 lines contains two integers uiu_{i} , viv_{i} ( 1<=ui,vi<=n1<=u_{i},v_{i}<=n , uiviu_{i}≠v_{i} ) representing a connection in Jacob's tree between balls uiu_{i} and viv_{i} .

输出格式

Print a single integer — the maximum grade Jacob can get by picking the right root of the tree and rearranging the list of neighbors.

输入输出样例

  • 输入#1

    5 3
    3 6 1 4 2
    1 2
    2 4
    2 5
    1 3
    

    输出#1

    3
    
  • 输入#2

    4 2
    1 5 5 5
    1 2
    1 3
    1 4
    

    输出#2

    1
    

说明/提示

In the first sample, Jacob can root the tree at node 22 and order 22 's neighbors in the order 44 , 11 , 55 (all other nodes have at most two neighbors). The resulting preorder traversal is 22 , 44 , 11 , 33 , 55 , and the minimum aia_{i} of the first 33 nodes is 33 .

In the second sample, it is clear that any preorder traversal will contain node 11 as either its first or second node, so Jacob cannot do better than a grade of 11 .

首页