Travelling Caterpillar
InterviewTime limit1sMemory limit1024 MB
Find the shortest closed walk from root 0 that visits every marked node in a weighted tree, and print its total length.
Problem
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. Between every pair of nodes, there is exactly one way to travel from one to the other.

Figure 1: Lilith's route through the tree.
Input
The first line contains two integers (), the number of nodes in the tree, and (), the number of leaves Lilith wants to munch.
The next lines describe the branches. The th line contains three integers , (, ), and (). This means there is a branch between nodes and that takes time to cross. If the tree is rooted at node , then is the parent of , so lies on the unique path from to . Lilith always starts at the root node .
The last line contains distinct integers (), the nodes that contain leaves Lilith wants to munch.
Output
Print the length of the shortest path that starts and ends at the root along the branches and lets Lilith munch all the leaves.