[A] NOIP2012 day2 epidemic control

Time limit: 20000 MS    Space limitations: 128000 KB
Benchmark Description: 2s, 128m
Problem Description

State-owned H n cities, cities with the n n-1 bidirectional path interconnected constitutes a tree, No. 1 is the capital city, is also the root of the tree.
H capital of the country broke out the dangers of a high infectious disease. Authorities in order to control the epidemic, to prevent spread of the epidemic (city leaf nodes represented) border city, decided to use military force to establish checkpoints in some cities, so that from the capital to the border city of each path has at least one checkpoint, border cities can also create a checkpoint. However, particular attention is that the capital can not be established checkpoints. Now, in some cities in the country H has stationed troops there, and a city could be stationed more troops.

An army can move between road links to the city and to establish checkpoints in any city other than the capital, and only a checkpoint in the city. An army after a road move from one city to another city needed time equal to the length of the road (unit: hour). Will the minimum number of hours required to control the epidemic. Note: Different forces can move simultaneously.

Input Format

A first line integer n, the number of cities.
The next n-1 lines of three integers, u, v, w, between each two integers separated by a space, u represents from city to city v w has a length of the road. Ensure that the input data is a tree, the root node and the number 1.
The next line an integer m, indicates the number of forces.
The next line of m integers, each between two integers separated by a space, respectively, these m army stationed in the city's number.

Output Format

A total of one line containing an integer that represents the minimum time to control the epidemic needs. If you can not control the epidemic output -1.

Sample input 1


1 2 1 
1 3 2 
3 4 3 

2 2 

Sample output 1

3

Sample input 2

10
2 1 3
2 3 4
1 4 7
5 1 9
6 1 2
4 7 9
7 8 8
9 8 8
1 10 2
5
2 8 5 4 2 

Sample output 2

9

Sample input 3

10
1 2 15606
3 1 2777
4 3 2008
1 5 29898
1 6 31457
7 5 4630
6 8 32496
3 9 27660
10 9 29090
4
9 5 10 3 

Sample output 3

56750

prompt

Example Description [O]
First Army checkpointed at point 2, the second support point is moved forces from 2 to 3 o'clock checkpointed, the time required was 3 hours.

[The scope of data
to ensure that troops will not be stationed in the capital.
For 20% of the data, 2≤ n≤ 10;
for 40% of data, 2 ≤n≤50,0 <w <105;
for 60% of data, 2 ≤ n≤1000,0 <w <106 ;
for 80 % of data, 2 ≤ n≤10,000;
to 100% of the data, 2≤m≤n≤50,000,0 <w <109.

【analysis】
  
[Standard] Cheng

Guess you like

Origin www.cnblogs.com/Limbo-To-Heaven/p/11372439.html