#P6419. [COCI 2014/2015 #1] Kamp
[COCI 2014/2015 #1] Kamp
Problem Description
There is a tree with nodes and edges. Passing through each edge costs a certain amount of time, and any two nodes are connected.
There are people (located at 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 people back to their respective homes.
Please answer: for , if the party is held at node , what is the minimum time the driver needs to send all people back home.
Input Format
The first line contains two integers .
The next lines each contain three numbers , meaning there is an edge between and that costs time.
The next lines each contain one number, indicating the locations of the people.
Output Format
Output numbers.
The number on line means: if the party is held at node , 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 of the testdata, .
- For of the testdata, , , .
Translated by ChatGPT 5