Under construction

Still being built. Things may change

Grain

Time limit3sMemory limit1024 MB

Summary
After each prince's castle is built, print twice the sum of road distances over all pairs of castles, counting village 1 as a castle.
Level

Medium7 of 10

Topics
Tree, Segment tree, DFS
Solved
No attempts yet

Problem

Bajtocja is a beautiful land, fairly ruled by King Bajtazar 222nd. It has nn villages numbered from 1 to nn. The villages are connected by n−1n-1 roads that form a connected network. The king's castle stands in village 1.

The king has kk sons who will soon come of age. Each adult prince needs a castle of his own, so new castles will be built in some villages.

The king and his sons must communicate about matters such as the safety of Bajtocja. For this, messengers are sent every day from each castle to every other castle. The horses that carry the messengers must eat grain before each trip, and each horse eats 1 decagram of grain per kilometer traveled.

Two castles need two messengers to communicate fully: one leaves the first castle for the second, and the other leaves in the opposite direction. Write a program that computes Bajtocja's daily grain demand after each new castle is built.

Input

The first line contains two integers nn and kk (1≤k<n≤1000001 \le k < n \le 100000), the number of villages and the number of princes.

Each of the next n−1n-1 lines contains three integers aa, bb, and cc (1≤a,b≤n1 \le a, b \le n, 1≤c≤10001 \le c \le 1000), describing a road of length cc kilometers between villages aa and bb.

Each of the next kk lines contains one integer dd (2≤d≤n2 \le d \le n), the village where the next prince builds his castle. No village gets more than one castle, so all values of dd are pairwise distinct.

Output

Print kk lines. The ii-th line contains the amount of grain (in decagrams) that the messengers need after the castle of the ii-th prince is built.

Examples1

  1. Example 1

    Input
    5 3
    1 4 3
    3 1 6
    1 2 5
    4 5 1
    5
    3
    2
    
    Expected output
    8
    40
    90