#C4176. Maximizing Unique Flower Species in a Garden

    ID: 47685 Type: Default 1000ms 256MiB

Maximizing Unique Flower Species in a Garden

Maximizing Unique Flower Species in a Garden

You are given a garden represented as an undirected graph with N flower beds and M connections between them. Each flower bed has a certain number of unique flower species. Your task is to determine the maximum sum of flower species available in any connected component of the garden.

In each test case, you are provided with:

  • The number of flower beds and the number of connections.
  • A list of integers where each integer represents the number of flower species in a corresponding flower bed.
  • A list of connections, each connection indicating that two flower beds are directly connected. Note that self connections are allowed.

You must use these inputs to compute the connected component with the highest total number of flower species and output that maximum sum.

Note: The input is taken from standard input (stdin) and the output should be printed to standard output (stdout). All formulas in the problem description conform to the LaTeX format if needed.

inputFormat

The input begins with an integer T (the number of test cases). For each test case:

  1. A line containing two integers N and M where 1 ≤ N ≤ 105 is the number of flower beds and 0 ≤ M ≤ 105 is the number of connections.
  2. A line containing N space-separated integers; the i-th integer represents the number of unique flower species at the i-th flower bed.
  3. M lines follow, each containing two integers u and v (0 ≤ u, v < N) representing an undirected connection between flower bed u and flower bed v.

All input is read from standard input (stdin).

outputFormat

For each test case, output a single line with one integer: the maximum sum of unique flower species that can be obtained from any connected component in the garden. This output should be printed to standard output (stdout).

## sample
1
4 4
3 4 2 1
0 1
1 2
2 3
3 0
10

</p>