题目描述
Problem Description
There is a tree with $ N $ vertices, numbered from $ 1 $ to $ N $. Among the $ N-1 $ edges, the $ i $th edge connects vertices $ A_i $ and $ B_i $ with weight $ V_i $ in both directions.
There are $ X $ Tapichans and $ Y $ Tapucans. Initially, the $ j $th Tapichan is at vertex $ P_j $, and the $ k $th Tapucan is at vertex $ Q_k $. Multiple Tapichans or Tapucans do not exist on the same vertex.
All Tapichans can repeatedly move to adjacent vertices. However, Tapichans and Tapucans do not get along. If a Tapichan moves to a vertex where a Tapucan is located, it might feel uncomfortable.
Therefore, we want to remove some edges to prevent all Tapichans from moving to vertices where Tapucans are located. Find the minimum total weight of the edges to be removed.
Input Format
The input is given from the standard input in the following format:
$ N $ $ X $ $ Y $ $ A_1 $ $ B_1 $ $ V_1 $ $ A_2 $ $ B_2 $ $ V_2 $ $ : $ $ A_{N-1} $ $ B_{N-1} $ $ V_{N-1} $ $ P_1 $ $ P_2 $ $ ... $ $ P_X $ $ Q_1 $ $ Q_2 $ $ ... $ $ Q_Y $
Output Format
Output the answer in one line.
Sample Input and Output
Sample Input #1
5 4 1
1 2 1
2 3 2
3 4 3
4 5 4
1 2 4 5
3
Sample Output #1
5
Sample Input #2
6 2 2
1 2 6
1 3 3
1 4 4
3 5 2
3 6 2
1 2
5 6
Sample Output #2
3
Notes/Hints
Constraints
- $2 \leq N \leq 5 \times 10^5$
- $1 \leq X, Y \leq N$
- $1 \leq A_i < B_i \leq N$
- $1 \leq V_i \leq 10^9$
- $1 \leq P_j, Q_k \leq N$
- $ P_1, P_2, ..., P_X, Q_1, Q_2, ..., Q_Y $ are distinct
- The given graph is a tree
- All inputs are integers
Partial Points
- If you solve the dataset where $N \leq 500$ correctly, you will be awarded $ 40 $ points.
Sample Explanation 1
Remove the 2nd and 3rd edges. In this case, no Tapichan can move to vertex $ 3 $ where the Tapucan is located.
Sample Explanation 2
Remove the 2nd edge.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分