|
||||||||||
City UpgradingTime Limit: 12000/6000 MS (Java/Others) Memory Limit: 524288/131072 K (Java/Others)Total Submission(s): 2457 Accepted Submission(s): 908 Problem Description The city where crazyzhk resides is structured as a tree. On a certain day, the city's network needs to be upgraded. To achieve this goal, routers need to be deployed. Each router covers the node it is placed on and its neighboring nodes. There is a cost $a_i$ associated with placing a router at each node. The question is: How can the routers be deployed at minimum cost to ensure that every node is covered? Input The input consists of multiple test cases. The first line contains a single integer $t(1≤t≤1000)$ — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $n$ $(2≤n≤ 10^5)$ — the number of the vertices in the given tree. The second line of each case are $n$ integers $a_i(1\le a_i \le 10^5)$,denoting the cost of setting up a router at each node. Each of the next $n-1$ lines contains two integers $u$ and $v$ ($1≤u,v≤n$, $u \neq v$) meaning that there is an edge between vertices $u$ and $v$ in the tree. The data guarantees that the sum of $n$ will not exceed $2\cdot 10^5$ Output For each test case print a single integer ——the minimum cost to ensure that every node is covered Sample Input
Sample Output
Source | ||||||||||
|