#P1084. [NOIP 2012 提高组] 疫情控制

    ID: 84 远端评测题 2000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心树形结构2012倍增二分NOIp 提高组排序

[NOIP 2012 提高组] 疫情控制

Description

Country H has nn cities. These nn cities are connected by n1n-1 bidirectional roads to form a tree. City 11 is the capital and is the root of the tree.

A highly dangerous contagious disease has broken out in the capital. To control the epidemic and prevent it from spreading to border cities (cities represented by leaf nodes), the authorities decide to deploy the army to set up checkpoints in some cities so that every path from the capital to any border city contains at least one checkpoint. Checkpoints may also be set in border cities. Note in particular that no checkpoint may be set in the capital.

Currently, troops are already stationed in some cities of Country H, and multiple troops may be stationed in the same city. A troop can move between adjacent cities along roads and can set up a checkpoint in any city except the capital. Each troop can set a checkpoint in only one city. The time for a troop to move across a road from one city to another equals the length of that road (unit: hours).

What is the minimum number of hours needed to control the epidemic? Note that different troops can move simultaneously.

Input Format

The first line contains an integer nn, the number of cities.

The next n1n-1 lines each contain 33 integers, u,v,wu, v, w, separated by single spaces, indicating there is a road of length ww between cities uu and vv. It is guaranteed that the input forms a tree, and the root is city 11.

The next line contains an integer mm, the number of troops.

The next line contains mm integers, separated by single spaces, indicating the cities where the mm troops are stationed.

Output Format

Output a single integer, the minimum time needed to control the epidemic. If it is impossible to control the epidemic, output 1-1.

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

Hint

Sample explanation:

The first troop sets a checkpoint at city 22, and the second troop moves from city 22 to city 33 to set a checkpoint. The time needed is 33 hours.

Constraints:

It is guaranteed that no troop is stationed in the capital.

  • For 20%20\% of the testdata, 2n102 \le n \le 10.
  • For 40%40\% of the testdata, 2n502 \le n \le 50, 0<w<1050 < w < 10^5.
  • For 60%60\% of the testdata, 2n10002 \le n \le 1000, 0<w<1060 < w < 10^6.
  • For 80%80\% of the testdata, 2n1042 \le n \le 10^4.
  • For 100%100\% of the testdata, 2mn5×1042 \le m \le n \le 5 \times 10^4, 0<w<1090 < w < 10^9.

NOIP 2012 Senior Day 2, Problem 3.

Translated by ChatGPT 5