Ensure that you are logged in and have the required permissions to access the test.
You are given an undirected weighted graph G with N nodes and M edges. Each edge has a weight assigned to it. You are also given an array A of N elements. Graph G does not contain any self-loops and multiple edges.
If a new edge is added between node u and v, then the weight of this edge is max(A[u],A[v]).
Add some edges (possible 0) until there exists a subgraph H such that it satisfies the following conditions:
Find the minimum possible weight of such subgraph H. The weight of a graph is defined as the summation of weights of all the edges present in the graph.
Note
Input format
Output format
For each test case, print the minimum possible weight of subgraph H. Print the output for each test case in a new line.
Constraints
1≤T≤101≤N≤1051≤A[i]≤1090≤M≤1051≤w≤109