You are given a map of a country in the form of an acyclic graph with m nodes. Each node represents an individual state connected to each other through bidirectional roads. During a war, enemy has occupied the country and placed 1 tank in each of the states mentioned in the input. The tanks use bidirectional roads to travel to any state. If any two tanks reach the same state, then the state will be destroyed. You need to stop two tanks from entering into the same state. In order to do so, you need to eliminate(opimally) the roads connecting any two states in which the tanks are placed. You need to find the least amount of time required to eliminate the connecting roads. Eliminating roads will take a certain amount of time mentioned in input.
Note:
The number of states and tanks is always greater than 1.
If there are m number of states, then they are numbered from 0 to m-1, i.e. state0, state1, up to state m-1.
The time required to eliminate the road connecting two states must always be positive and greater than 0.
Constraints:
1 <m < 200
1 < number of tanks < 200
Input Format:
The first line contains two space-separated integers m and n, where m and n denote the number of states and the number of tanks respectively.
Each of the following m-1 lines contains three space-separated integers denoting two connected states(say,state1 and state2) and time,the duration reqd. to eliminate the road connecting "state1" and "state2".
The following n lines each contain an integer denoting the state having a tank.
Output
Print the least amount of time reqd. to eliminate the connecting roads to protect all the states from destruction.
Example:
Input:
6 4
0 4 1
0 5 3
4 2 4
4 3 2
3 1 5
3
1
2
5
Output:
8
Explanation:
States 1,3,2 and 5 each have a tank. Minimum time required to save all the states is 1+2+5=8, i.e. eliminating roads connecting State 0 and 4, State 4 and 3,State 3 and 1.
Any approach to solve the question,thanks in advance.