#2525. [POI2011] Dynamite

[POI2011] Dynamite

简要题意

给一棵树,树上有一些关键节点,要求你选 mm 个点,第 ii 个关键节点到这些点中每个点距离的最小值记为 disidis_i,记这全部 disdis 的最大值为 KK,现在要使 KK 最小,求这个 KK

Description

The Byteotian Cave is composed of nn chambers and n1n-1 corridors that connect them. For every pair of chambers there is unique way to move from one of them to another without leaving the cave.

Dynamite charges are set up in certain chambers.

A fuse is laid along every corridor.

In every chamber the fuses from the adjacent corridors meet at one point, and are further connected to the dynamite charge if there is one in the chamber. It takes exactly one unit of time for the fuse between two neighbouring chambers to burn, and the dynamite charge explodes in the instant that fire reaches the chamber it is inside.

We would like to light the fuses in some mm chambers (at the joints of fuses) in such a way that all the dynamite charges explode in the shortest time possible since the fuses are lit. Write a program that will determine the minimum such time possible.

Input

The first line of the standard input holds two integers nn and mm, separated by a single space, that denote, respectively, the number of chambers in the cave and the number of chambers in which fire can be set to the fuses.

The chambers are numbered from 11 to nn.

The next line contains nn integers d1, d2, , dnd_1,\ d_2,\ \cdots,\ d_n, separated by single spaces.

If di=1d_i=1, then there is dynamite in the ii-th chamber, and if di=0d_i=0, there is none.The following n1n-1 lines specify the corridors of the cave. Each of them holds two integers a, ba,\ b, separated by a single space, denoting that there is a corridor connecting the chambers aa and bb. Every corridor appears exactly once in the description.

Output

The first and only line of the standard output should hold a single integer, equal to the minimum time it takes from lighting the fuses to the explosion of all the charges.

7 2
1 0 1 1 0 1 1
1 3
2 3
3 4
4 5
5 6
5 7
1

Constraints

For 10%10\% data, n10n\leq 10.

For 40%40\% data, n103n\leq 10^3.

For 100%100\% data, 1mn3×1051\leq m\leq n\leq 3\times 10^5, di{0, 1}d_i\in\{0,\ 1\}, 1a<bn1\leq a<b\leq n.