#P9861. Coloration
Coloration
Coloration
Problem Description
For a connected undirected graph,where every vertex has a value, every edge has a unique weight. We define the limit of a path as the maximum edge weights of all edges on the path. The limiting edge between two vertexes is the edge with the maximum weight in the path,and this path has to be with the minimum limit between two vertexes( if ), and the value of is uniquely certain for graphs with edge weights are different. Define each edge of the limit set {$u|1\leq u\leq n,\exists x: \ S(u,x)=w,val(u)\ge val(w)$} ( is a vertex) represents the value of vertex , represents edge weights. Now you need to dye each vertex black and white, for the th vertex, the cost of dyeing it black is , the cost of dyeing it white is , for each edge , we need to satisfy that the number of black vertexes in does not exceed and the number of white vertexes does not exceed . What is the minimum dyeing cost if the conditions are met?
Input
The first line input a positive integer , representing the number of test data. For each test data: In the first line, input two positive integers , representing the number of vertexes and the number of edges in the graph. In the next row, the three positive integers $a_i,b_i,val(i)(0\leq a_i,b_i\leq 10^5,1\leq val(i)\leq m)$represent the cost of dyeing the th vertex black, the cost of dyeing the th vertex white, and the vertex weight. In the next row, the three positive integers in each row $u_i,v_i,val(i)(1\leq u_i,v_i\leq n(u\neq v),1\leq val(i)\leq m)$represent an undirected edge and its weight . The next line contains integers represents the upper limit on the number of black vertexes in the limit set of edges. The next line contains integers represents the upper limit on the number of white vertexes in the limit set of edges.
Output
Output an integer representing the minimum cost of dyeing. It is guaranteed that there is a method that meets the requirements and all edge weights are different.
Sample Input
1
5 5
5 3 3
3 5 2
4 1 1
2 3 2
3 4 1
1 2 3
1 3 1
2 5 2
2 4 4
1 4 5
1 1 1 1 1
1 1 1 1 1
Sample Output
14
Hint
For example represents the limited set of edges numbered The optimal solution is to dye vertex 3 white and the remaining vertexes black.
Source
2023“钉耙编程”中国大学生算法设计超级联赛(6)