406202: GYM102309 D Director of Orz Pandas

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Director of Orz Pandastime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Prof. Xie is a highly reputated scholar from SAST and the director of an important research program related to Orz Pandas. The Orz Pandas are telling a story of Prof. Xie to other pandas:

Once upon a time Prof. Xie wanted to buy a new house. He wanted the house to have $$$n$$$ features, and his spouse, Prof. Zhang wanted other $$$m$$$ features. Unfortunately, features wanted by Prof. Xie may conflict with features wanted by Prof. Zhang.

A panda wants to solve this situation mathematically. He assigns one weight $$$w_i$$$ for each feature $$$i$$$ and trys to choose some features with no conflicting pairs and maxmizing the sum of weights of choosen features.

Now you should tell him the maximized weight sum so he can check his solution.

Input

There are multiple test cases. Please process until EOF.

For each test case, the first line contains two integers $$$n$$$ and $$$m$$$.

The second line contains $$$n+m$$$ integers $$$w_1, \cdots, w_{n+m}$$$. $$$w_i$$$ is the weight of the $$$i$$$-th feature. The $$$1, 2, \cdots, n$$$-th features are wanted by Prof. Xie and the other features are wanted by Prof. Zhang.

The third line contains an integer $$$k$$$. Each of the next $$$k$$$ lines contains two integers $$$p_i$$$ and $$$q_i$$$, representing the $$$p_i$$$-th feature conflicts with the $$$q_i$$$-th feature.

It's guaranteed $$$1 \leq n, m \leq 100$$$, $$$1 \leq k \leq 10000$$$, $$$1 \leq w_i \leq 10^7$$$, $$$1 \leq p_i \leq n$$$, $$$n < q_i \leq n+m$$$.

Output

For each test case, output one line containing the answer.

ExampleInput
2 2
4 3 8 2
3
1 3
1 4
2 4
Output
11

加入题单

算法标签: