Travelling Caterpillar

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Lilith is a hungry caterpillar! From her vantage point at the root of a tree, she has identified some leaves she wishes to munch before returning to the root. She wants to finish munching all of them as quickly as possible so that she will grow into a plump, buttery butterfly.

The tree Lilith occupies is a bit unusual. We can view it as a collection of nodes, where some of the nodes contain leaves that Lilith wishes to munch. Each branch connects exactly two nodes together. It is guaranteed that between every pair of nodes, there is precisely one way to travel from one to the other.

Given a description of the tree and which nodes have leaves that Lilith wishes to munch, can you help Lilith route her munching by minimizing the time she must travel?

Figure 1: Illustration of Sample Input 11. Lilith can munch the nodes at leaves 2,3,62,3,6 and return to the root 00 by following the following sequence of nodes: 046401213100→4→6→4→0→1→2→1→3→1→0. The total distance Lilith travels is the length of each branch she crossed in this sequence: 2+3+3+2+5+1+1+4+4+5=302+3+3+2+5+1+1+4+4+5=30.

입력

The first line of input contains two integers NN (1N10001≤N≤1000), which is the number of nodes in the tree, and KK (1KN1≤K≤N), which is the number of leaves to be munched.

The next N1N-1 lines of input describe the branches (edges) of the tree. The iith such line contains three integers s_is\_it_it\_i (0s_i,t_i\<N0≤s\_i,t\_i\<N, s_it_is\_i≠t\_i), and d_id\_i (0d_i1060≤d\_i≤10^6). This indicates there is a branch between node s_is\_i and node t_it\_i which takes d_id\_i time to cross. Furthermore, if we view the tree as rooted at node 00, we have that s_is\_i is the parent of t_it\_i (i.e. s_is\_i lies on the unique path from 00 to t_it\_i). Lilith always starts at the root node 00.

The last line of input contains KK distinct integers a_1,,a_Ka\_1,\dots ,a\_K (0a_i\<N0≤a\_i\<N), which indicates the nodes containing leaves that Lilith wants to munch.

출력

Display the length of the shortest path along the branches of the tree, starting and ending at the root, which allows Lilith to eat all leaves.