#P3523. Minimum Explosion Time in Byteotian Cave

    ID: 16777 Type: Default 1000ms 256MiB

Minimum Explosion Time in Byteotian Cave

Minimum Explosion Time in Byteotian Cave

The Byteotian Cave consists of \(n\) chambers connected by \(n-1\) corridors such that there is a unique path between any two chambers (i.e. the chambers and corridors form a tree). Some chambers contain dynamite charges. A fuse is laid along every corridor. In every chamber the adjacent fuses meet and are connected to the dynamite charge (if one is present).

The fuse takes exactly one time unit to burn through a corridor, and a dynamite charge explodes at the instant the flame reaches its chamber. We want to choose \(m\) chambers at which to light the fuses (at the joint of fuses) so that all dynamite charges explode as soon as possible. In other words, if we denote the (minimum) time it takes the fire to reach a chamber containing a dynamite charge (from the nearest lit chamber) by \(t\), our aim is to minimize \(\max\{t\}\) over all chambers with a dynamite charge.

Given the structure of the cave, the locations of the dynamite charges and the number \(m\) of chambers where the fuse is lit initially, determine the minimum explosion time achievable by an optimal choice of chambers to light.

Note: All formulas are given in \(\LaTeX\) format.

inputFormat

The first line contains three space-separated integers \(n\), \(m\) and \(k\) \((1 \leq m \leq n \leq 10^5)\): the number of chambers, the number of chambers where the fuses are lit initially, and the number of chambers containing dynamite, respectively.

The second line contains \(k\) distinct integers \(a_1, a_2, \ldots, a_k\) \((1 \leq a_i \leq n)\) indicating the indices of the chambers containing dynamite charges.

The following \(n-1\) lines each contain two space-separated integers \(u\) and \(v\) \((1 \leq u, v \leq n)\) describing a corridor connecting chambers \(u\) and \(v\).

outputFormat

Output a single integer representing the minimum time (in time units) needed such that, by optimally choosing \(m\) chambers to light the fuses, every dynamite charge is reached by the flame within that time.

sample

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