#P7774. Total Eclipse
Total Eclipse
Total Eclipse
Problem Description
There are cities and bidirectional roads in Byteland. These cities are labeled by , the brightness of the -th city is . Magician Sunset wants to play a joke on Byteland by making a total eclipse such that the brightness of every city becomes zero. Sunset can do the following operations for arbitrary number of times: · Select an integer (). · Select distinct cities () such that they are connected with each other. In other words, for every pair of distinct selected cities and , if you are at city , you can reach city without visiting cities not in . · For every selected city (), decrease by . Note that Sunset will always choose with the maximum possible value. Now Sunset is wondering what is the minimum number of operations he needs to do, please write a program to help him.
Input
The first line of the input contains a single integer (), the number of test cases. For each case, the first line of the input contains two integers and (, ), denoting the number of cities and the number of roads. The second line of the input contains integers (), denoting the brightness of each city. Each of the following lines contains two integers and (), denoting an bidirectional road between the -th city and the -th city. Note that there may be multiple roads between the same pair of cities.
Output
For each test case, output a single line containing an integer, the minimum number of operations.
Sample Input
1
3 2
3 2 3
1 2
2 3
Sample Output
4
Source
2020 Multi-University Training Contest 2