#P7201. [COCI 2019/2020 #1] Džumbus

[COCI 2019/2020 #1] Džumbus

Problem Description

Marin is a kind person, so he will organize QQ parties for his NN friends. The only drink at the parties is called džumbus.

Each friend’s required amount of this drink is known. Among these friends, there are MM pairs of friends. In each pair, after both of them have their own requirements satisfied, they will start checking each other’s answers to previous COCI problems.

When friend AA shares their answers with friend BB, friend BB may decide whether to share in the same way. However, among these MM pairs, it is impossible for BB to re-share the answers that AA shared with others back to AA.

Marin prepares a different total amount of džumbus for each party. During each party, he wants to maximize the number of friends who share answers with someone at least once.

Your task is to find the maximum number of friends who will share answers with others.

Input Format

The first line contains two integers NN and MM as mentioned in the statement.

The second line contains NN integers, where the ii-th integer is DiD_i, representing the amount of drink required by the ii-th friend.

The next MM lines each contain two integers Ai,BiA_i, B_i (AiBiA_i \neq B_i), representing the ii-th pair of friends.

The next line contains an integer QQ.

The next QQ lines each contain one integer SiS_i, representing the total amount of drink for the ii-th party.

Output Format

Output the answer for each party, i.e. the maximum number of friends who will share answers with others.

Print the answers of consecutive parties separated by a newline.

1 0
1000
1
1000
0
3 2
1 2 3
1 2
1 3
3
2
3
5
0
2
2
14 13
2 3 4 19 20 21 5 22 6 7 23 8 10 14
1 2
1 3
1 4
2 5
2 6
3 7
3 8
3 9
4 10
8 11
10 13
10 12
12 14
3
45
44
23
8
7
5

Hint

Sample Explanation

In the first party of the third sample, Marin decides to let friends numbered 1,2,3,7,9,10,12,131,2,3,7,9,10,12,13 reach their respective required amounts. They drink a total of 4545 units of drink.

As shown in the figure below, build an undirected graph where vertices represent friends and edges represent whether two friends form a pair. Here, exchange indicates that the two friends exchange answers.

Constraints and Notes

Subtask Points Constraints and Notes Special Property
11 2020 M=N1,1Si1000M = N - 1, 1 \le S_i \le 1000 Each friend shares answers with at most two other friends
22 3030 M=N1M = N - 1
33 N100N \le 100 None
44 None

For 100%100\% of the testdata, $0 \le M \lt N \le 1000, 1 \le Q \le 2 \times 10^5, 1 \le D_i \le 10^9, 1 \le S_i \le 10^9$.

Notes

The scoring of this problem follows the original COCI problem settings, with a full score of 110110.

Translated from T3 Džumbus of COCI2019-2020 CONTEST #1.

Translated by ChatGPT 5