#266. [POI2011] DYN-Dynamite
[POI2011] DYN-Dynamite
[POI2011] DYN-Dynamite
题面翻译
给一棵树,树上有一些关键节点,要求你选 个点,第 个关键节点到这些点中每个点距离的最小值记为 ,记这全部 的最大值为 ,现在要使 最小,求这个 。
题目描述
The Byteotian Cave is composed of chambers and 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 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.
输入格式
The first line of the standard input holds two integers and (), 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 1 to .
The next line contains integers (), separated by single spaces.
If , then there is dynamite in the -th chamber, and if , there is none.The following lines specify the corridors of the cave. Each of them holds two integers (), separated by a single space, denoting that there is a corridor connecting the chambers and . Every corridor appears exactly once in the description.
You may assume that in tests worth 10% of the points it holds additionally that , while in tests worth 40% of the points it holds that
输出格式
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.
样例 #1
样例输入 #1
7 2
1 0 1 1 0 1 1
1 3
2 3
3 4
4 5
5 6
5 7
样例输出 #1
1