#K38957. Max Skill Sum in Collaborative Groups
Max Skill Sum in Collaborative Groups
Max Skill Sum in Collaborative Groups
You are given a set of participants each with a certain skill level. Some pairs of participants can collaborate, forming undirected connections between them. When participants are connected (directly or indirectly), their skills contribute together as a group.
Your task is to compute the maximum possible sum of skill levels, which is defined as the sum of the skills of every participant in each connected component. Note that the parameter k
is provided but does not affect the computation.
The participants are numbered starting from 1. Two participants can collaborate if there is a given pair connecting them.
Input Example:
5 4 1 2 3 4 5 4 1 2 2 3 3 4 4 5
Output Example:
15
inputFormat
The first line contains two integers n
and k
, where n
is the number of participants, and k
is the number of allowed collaborative pairs (unused in the solution).
The second line contains n
space-separated integers representing the skill levels of the participants.
The third line contains an integer m
which indicates the number of pairs provided.
Each of the next m
lines contains two integers u
and v
indicating that participant u
can collaborate with participant v
.
outputFormat
Output a single integer: the maximum sum of skill levels obtained by summing the skills in each connected component.
## sample5 4
1 2 3 4 5
4
1 2
2 3
3 4
4 5
15
</p>