Marin is a good man, so he'll organize parties for his friends, all of whom are competitive programmers. The only drink that is going to be served at his parties will be džumbus — a mixture of Coke and ginger juice. For each of his friends, Marin knows the amount of džumbus they need to drink in order to relax. He also knows that there are pairs of people among his friends such that, if both of them are relaxed, they will begin to exchange the solutions of past COCI problems (since there are no published editorials). When a person shares their solutions with person , the person may decide to share those solutions in the same manner, but it is also known that pairs are formed in a way that it is impossible that those solutions will get back to person during that party, regardless of the order in which exchanges took place. Marin has prepared different amounts of džumbus for each party. During each party, he will distribute the drink in a way which maximizes the number of people that will at least once exchange their solutions with another person at that party. Your task is to determine the number of people that will exchange their solutions for each of the parties.
Input
The first line contains integers and from the task description. The second line contains space separated integers , the amounts of džumbus needed to relax Marin's friends, given in order from a friend number to a friend number . The th of the next lines contains two integers and , denoting a pair of friends from the task description. The next line contains an integer from the task description. The next lines contain a single integer which represents the total amount of džumbus that is going to be served at th party.
Output
Output the number of people that will exchange their solutions for each of the parties. The answer for each party should be given in a separate line. Note that the parties are independent of each other.
Scoring
In all subtasks, it holds , , , and .
Subtask | Score | Constraints |
---|---|---|
1 | , , Marin's friends will be paired up in a way that each friend will exchange their solutions with at most two other people. | |
2 | , Marin's friends will be paired up in a way that each friend will exchange their solutions with at most two other people. | |
3 | ||
4 | No additional constraints. |
Sample Input 1
1 0
1000
1
1000
Sample Output 1
0
Sample Input 2
3 2
1 2 3
1 2
1 3
3
2
3
5
Sample Output 2
0
2
2
Sample Input 3
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
Sample Output 3
8
7
5
Explanation of Sample Output 3
At the first party, Marin decided to relax friends with indices 1, 2, 3, 7, 9, 10, 12, and 13. They have drunk a total of 45 units of džumbus.
Comments