Codeforces Round 1021 (Div. 2)
D
Baggage Claim
Codeforces
未评级
原题
← CE →
翻译中…

Every airport has a baggage claim area, and Balbesovo Airport is no exception. At some point, one of the administrators at Sheremetyevo came up with an unusual idea: to change the traditional shape of the baggage claim conveyor from a carousel to a more complex form.

翻译中…

Suppose that the baggage claim area is represented as a rectangular grid of size $n \times m$. The administration proposed that the path of the conveyor should pass through the cells $p_1, p_2, \ldots, p_{2k+1}$, where $p_i = (x_i, y_i)$.

翻译中…

For each cell $p_i$ and the next cell $p_{i+1}$ (where $1 \leq i \leq 2k$), these cells must share a common side. Additionally, the path must be simple, meaning that for no pair of indices $i \neq j$ should the cells $p_i$ and $p_j$ coincide.

翻译中…

Unfortunately, the route plan was accidentally spoiled by spilled coffee, and only the cells with odd indices of the path were preserved: $p_1, p_3, p_5, \ldots, p_{2k+1}$. Your task is to determine the number of ways to restore the original complete path $p_1, p_2, \ldots, p_{2k+1}$ given these $k+1$ cells.

翻译中…

Since the answer can be very large, output it modulo $10^9+7$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 3 \cdot 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains three integers $n$, $m$, and $k$ ($1 \le n, m \le 1000$, $n \cdot m \ge 3$, $1 \le k \le \left\lfloor \frac12 (n m - 1) \right\rfloor$) — the dimensions of the grid and a parameter defining the length of the path.

翻译中…

Next, there are $k+1$ lines, the $i$-th of which contains two integers $x_{2i-1}$ and $y_{2i-1}$ ($1 \le x_{2i-1} \le n$, $1 \le y_{2i-1} \le m$) — the coordinates of the cell $p_{2i-1}$ that lies on the path.

翻译中…

It is guaranteed that all pairs $(x_{2i-1}, y_{2i-1})$ are distinct.

翻译中…

It is guaranteed that the sum $n \cdot m$ over all test cases does not exceed $10^6$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the number of ways to restore the original complete path modulo $10^9+7$.

翻译中…

Note

翻译中…

In the first test case, there are two possible paths:

翻译中…
  • $(1,1) \to (2,1) \to (2, 2) \to (2, 3) \to (2, 4)$
  • $(1,1) \to (1,2) \to (2, 2) \to (2, 3) \to (2, 4)$
翻译中…

In the second test case, there is no suitable path, as the cells $(1,1)$ and $(1,4)$ do not have a common neighboring cell.

翻译中…

样例

Input #1
5
2 4 2
1 1
2 2
2 4
1 4 1
1 1
1 4
5 5 11
2 5
3 4
4 5
5 4
4 3
5 2
4 1
3 2
2 1
1 2
2 3
1 4
3 4 4
1 2
2 1
3 2
2 3
3 4
3 3 2
2 2
1 1
1 3
Output #1
2
0
2
5
1
InputCopy OutputCopy
题目信息
题号
2098D
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。