#P6419. [COCI 2014/2015 #1] Kamp

    ID: 6643 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2014树形 DPCOCI(克罗地亚)

[COCI 2014/2015 #1] Kamp

Problem Description

There is a tree with nn nodes and n1n-1 edges. Passing through each edge costs a certain amount of time, and any two nodes are connected.

There are KK people (located at KK different nodes) who want to gather at one node for a party.

After the party ends, a car needs to start from the party node, pick up all people into the car, and then send these KK people back to their respective homes.

Please answer: for i=1ni = 1 \sim n, if the party is held at node ii, what is the minimum time the driver needs to send all KK people back home.

Input Format

The first line contains two integers n,Kn, K.

The next n1n-1 lines each contain three numbers x,y,zx, y, z, meaning there is an edge between xx and yy that costs zz time.

The next KK lines each contain one number, indicating the locations of the KK people.

Output Format

Output nn numbers.

The number on line ii means: if the party is held at node ii, the minimum time the driver needs.

7 2
1 2 4
1 3 1
2 5 1
2 4 2
4 7 3
4 6 2
3
7
11
15
10
13
16
15
10
5 2
2 5 1
2 4 1
1 2 2
1 3 2
4
5

5
3
7
2
2

Hint

Constraints

  • For 50%50\% of the testdata, n2×103n \le 2 \times 10^3.
  • For 100%100\% of the testdata, 1Kn5×1051 \le K \le n \le 5 \times 10^5, 1x,yn1 \le x, y \le n, 1z1081 \le z \le 10^8.

Translated by ChatGPT 5