#1152
Unrated
KAMP
시간 제한
2s
메모리 제한
128MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

In a certain flooded village, a secret superhuman humanitarian camp is being opened as we speak. The village consists of N houses marked with integers from 1 to N. The houses are connected to each other with N-1 roads so that there is a unique way between each two houses. For each road, we know the time it takes for a truck to pass it. The camp should be put up in some house's garden, but the camp manager still hasn't decided which house it is going to be.

Mirko has been appointed as the driver. His job is to drive around teams of volunteers to the super truck from the camp to the houses where their teams will be put up to work. His van is super because its area can drive in if he wants, there are quite a few teams and the houses he needs to drop off at are quite all over the village.

All K teams board into Mirko's truck initially, and then he drives them to houses in the sequence he determined for himself. After he drives around all teams, Mirko stays and helps the last team (he doesn't go back to camp).

In order for the camp manager to determine where to put up the camp, he wants to know, for each house, the minimal time it takes for Mirko to drive around and help all teams if that house is the headquarters. Write a programme that will help him.

입력

The first line of input contains the integers N (2 ≤ N ≤ 500 000), and K (1 ≤ K ≤ N). Each of the following N-1 lines contains integers Ai, Bi (1 ≤ Ai, Bi ≤ N, 1 ≤ Gi ≤ 1 000 000), where Gi is the time it takes to pass a two-way road between houses Ai and Bi, respectively. The first line of the next K lines contains the integers that mark the houses where the K teams are located in the headquarters.

출력

Output N lines. The i-th line of output must contain the minimal times it takes Mirko to drive around all the teams if the camp headquarters is located in the i-th house.

예제 입력 1

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

예제 출력 1

5
3
7
2
2

예제 입력 2

7 2
1 2 4
1 3 1
2 5 1
2 4 2
4 7 3
4 6 2
3
7

예제 출력 2

11
15
10
13
16
15
10
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.