|
||||||||||
Weighted Beautiful TreeTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 547 Accepted Submission(s): 182 Problem Description A tree is a connected graph with $n$ nodes and $n-1$ edges. You are given a weighted tree with $n$ nodes. The $i$-th node has a weight of $wn_i$ and a cost of $c_i$. The $i$-th edge connecting node $u_i$ and $v_i$ has a weight of $we_i$. The edge is called beautiful if and only if it meets $\min(wn_{u_i}, wn_{v_i}) \le we_i \le \max(wn_{u_i}, wn_{v_i})$. You can do the following operation several times.
Input The first line contains an integer $T$, denoting the number of test cases. For each test case, the input format is as follows: | $n$ | | | | | |-----------|-----------|------------|----------|--------| | $c_1$ | $c_2$ | $c_3$ | $\ldots$ | $c_n$ | | $wn_1$ | $wn_2$ | $wn_3$ | $\ldots$ | $wn_n$ | | $u_1$ | $v_1$ | $we_1$ | | | | $u_2$ | $v_2$ | $we_2$ | | | | $\vdots$ | $\vdots$ | $\vdots$ | | | | $u_{n-1}$ | $v_{n-1}$ | $we_{n-1}$ | | | It is guaranteed that:
Output For each test case, output an integer in a single line, denoting the minimum total cost. Sample Input
Sample Output
Source | ||||||||||
|