#P4701. 粘骨牌
粘骨牌
Description
On an board, all cells except one are covered by dominoes, so there are dominoes in total.
Alice may make arbitrarily many moves. After each move, all dominoes must remain within the board, and no two dominoes may overlap.
There are several special cells on the board. Once any of them becomes exposed, you lose, so you must prevent Alice’s moves from exposing these cells.
You may choose to fix any number of dominoes in place. Fixing one domino costs a certain amount. As Bob, you want to pay the minimum total cost so that no matter how Alice moves, those special cells will never be exposed. Find this minimum cost.
If it is impossible no matter how you fix the dominoes, output "GG".
Input Format
The first line contains three integers $n, m, k(1 \leq n, m \leq 1001, 0 \leq k \leq n \times m)$, representing the size of the board and the number of special cells. It is guaranteed that and are both odd.
The next line contains numbers. The -th number denotes the cost to fix the -th domino.
The next lines each contain two integers , indicating that is a special cell. The special cells are not guaranteed to be distinct; if duplicates occur, ignore any later occurrence.
The next lines each contain numbers , describing the coverage of the board. If , that cell is uncovered; otherwise, it is covered by the domino numbered .
Output Format
Output a single line with the answer: either a single integer representing the minimum total cost, or GG if it is impossible.
3 3 1
5 5 5 5
1 1
0 1 1
2 3 4
2 3 4
GG
3 3 2
5 5 5 1
3 1
3 3
0 1 1
2 3 4
2 3 4
6
3 3 2
1 5 5 5
3 1
3 3
0 1 1
2 3 4
2 3 4
6
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号