This page is still under construction.

Parts of this page are still being built. What you see may change.

Volunteer Camp

Time limit2sMemory limit128 MB

Summary
Starting from each house in a weighted tree, find the shortest truck route that visits K marked houses without driving back.
Level

Hard8 of 10

Topics
Tree, Dynamic programming, DFS
Solved
No attempts yet

Problem

A village hit by a flood is opening a volunteer camp. The village has NN houses numbered 11 to NN, joined by N−1N-1 roads, so exactly one route runs between any two houses. Each road has a fixed time a truck needs to drive along it. The camp goes in the garden of one house, and the manager has not chosen that house yet.

Mirko drives the truck. His job is to carry volunteer teams from the camp to the house where each team works. Every team fits in the truck at the same time. There are KK teams and each team goes to a different house.

Mirko loads all KK teams at the camp, then drops them off in an order he picks himself. After the last team gets out, he stays in that house and helps, so he never drives back to the camp.

For every house, compute the minimal time Mirko needs to deliver all the teams when the camp is in that house.

Input

The first line contains two integers NN and KK (1≤N≤5000001 \le N \le 500000, 1≤K≤N1 \le K \le N).

Each of the next N−1N-1 lines contains three integers AA, BB, CC, meaning that a truck needs time CC to drive the two way road between house AA and house BB (1≤A,B≤N1 \le A, B \le N, 1≤C≤10000001 \le C \le 1000000).

Each of the next KK lines contains the number of the house one team is going to, one number per line. The KK numbers are distinct.

Output

Print NN lines. Line ii contains the minimal time Mirko needs to deliver all the teams when the camp is in house ii.

Note

Look at the first example. Starting from house 11, Mirko can drive to houses 22, 44, 22, 55 in that order. Starting from house 22, he can drive to houses 55, 22, 44.

Examples6

  1. Example 1

    Input
    5 2
    2 5 1
    2 4 1
    1 2 2
    1 3 2
    4
    5
    
    Expected output
    5
    3
    7
    2
    2
    
  2. Example 2

    Input
    7 2
    1 2 4
    1 3 1
    2 5 1
    2 4 2
    4 7 3
    4 6 2
    3
    7
    
    Expected output
    11
    15
    10
    13
    16
    15
    10
    
  3. Example 3

    Input
    1 1
    1
    
    Expected output
    0
    
  4. Example 4

    Input
    2 1
    1 2 1000000
    2
    
    Expected output
    1000000
    0
    
  5. Example 5

    Input
    6 2
    1 2 3
    2 3 4
    3 4 5
    4 5 6
    5 6 7
    1
    6
    
    Expected output
    25
    28
    32
    37
    32
    25
    
  6. Example 6

    Input
    5 4
    1 2 7
    1 3 5
    1 4 9
    1 5 2
    2
    3
    4
    5
    
    Expected output
    37
    30
    32
    30
    35