1567.Coin

Time Limit: 1s Memory Limit: 256MB

Little F went to a party this day, and now little F wants to organize everyone to play a game together!

A total of $N$ people participated in the game (Little F watched them play). Little F prepared $N$ identical coins. At the beginning, each person had exactly one coin, and each person had a number $a_i$ indicating the upper limit of coins he could held.

There are $M$ rounds in the game. In each round, Little F will choose two people $A$ and $B$ (of course, these two people are different), and then these two people have three choices:

  1. A gives B a coin
  2. B gives A a coin
  3. They do nothing

Note that at any time, the number of coins held by each person cannot exceed his holding limit $a_i$.

Among the $N$ people, there are $K$ people who are friends of Little F, and now little F wants to know, after $M$ rounds of games, in all possible situations, what is the maximum total number of coins held by his $K$ friends.

Input Format(From the terminal/stdin)

A positive integer $T$ in the first line represents the number of test groups, for each group of test data:

The first line contains three integers $N, M, K$. Respectively represent the total number of people, the number of game rounds and the number of friends of Little F.

The next line contains $N$ integers, and the $i$-th number $a_i$ represents the maximum number of coins held by the $i$-th person.

In the next $M$ lines, two integers $(A, B)$ are given in each line to indicate that the people selected in this round of the game are $A$ and $B$

The next line contains $K$ numbers $b_1,b_2...b_k$ represents the $K$ friends of Little F

$1≤T≤10,1≤N,M,a_i≤3000,1≤K≤N$

Output Format(To the terminal/stdout)

For each set of test data, the output line contains an integer, indicating the maximum total number of coins held by the $K$ friends of Little F.

Sample Input

Copy
2
4 4 1
4 4 4 4
1 4
4 3
3 2
2 1
1
5 4 2
1 3 1 2 2
1 3
3 4
1 5
2 5
2 4
 \n
 · · \n
 · · · \n
 · \n
 · \n
 · \n
 · \n
 \n
 · · \n
 · · · · \n
 · \n
 · \n
 · \n
 · \n
 · \n

Sample Output

Copy
3
4
 \n
 \n
Source: 2023“钉耙编程”中国大学生算法设计超级联赛(2)

Submit

请先 登录

© 2025 FAQs