Kohinoor

0

0 votes
Problem

N miners went for a quest to kollur mines to dig out diamonds.GOI has announced to reward the team with highest no of diamonds with an Airbus Helicopter

There are given M pairs of friends. If  X and Y are friends and Y and Z are friends, then X, Y, and Z are on the same team

You are given a list of integers A which contains the no of diamonds mined by each person.

Find the maximum no of diamonds a team should set aside for the reward.

 

Input:
First-line contains an integer T. First line of each test case contains two space-separated N and M. M lines follow. Each of the M lines contains two integers Xi and Yi. The last line of the test case contains an N space-separated integers constituting the array A 

Output:
Print the answer to each test case in a new line.

Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 105
0 ≤ M ≤ 105
0 ≤ Ai ≤ 1012

 

 

 

 

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

1, 2, and 3 are friends and thus forming the winning team with a total of 6 diamonds

Editor Image

?