#C9055. Maximum Connected Component Sum
Maximum Connected Component Sum
Maximum Connected Component Sum
You are given an undirected graph with N nodes and M edges. Each node is assigned an integer value. Your task is to compute the maximum possible sum of node values in any connected component of the graph.
For a connected component consisting of nodes with values \(v_1, v_2, \ldots, v_k\), the sum is given by \(\sum_{i=1}^{k} v_i\). You need to perform this calculation for several test cases.
The graph is represented using 1-indexed node numbering.
inputFormat
The input begins with an integer T denoting the number of test cases.
For each test case:
- The first line contains two integers N and M — the number of nodes and edges respectively.
- The second line contains N space-separated integers representing the values of the nodes.
- This is followed by M lines, each containing two integers u and v representing an undirected edge between nodes u and v.
outputFormat
For each test case, output a single integer indicating the maximum sum of node values among all connected components. Each result should be printed on a new line.
## sample3
4 2
1 2 3 4
1 2
2 3
5 0
1 2 3 4 5
6 3
1 2 3 4 5 6
1 2
3 4
5 6
6
5
11
</p>