Codeforces Round 978 (Div. 2)
E1
Billetes MX (Easy Version)
Codeforces
2500
原题
← D2E2 →
翻译中…

This is the easy version of the problem. In this version, it is guaranteed that $q = 0$. You can make hacks only if both versions of the problem are solved.

翻译中…

An integer grid $A$ with $p$ rows and $q$ columns is called beautiful if:

翻译中…
  • All elements of the grid are integers between $0$ and $2^{30}-1$, and
  • For any subgrid, the XOR of the values at the corners is equal to $0$. Formally, for any four integers $i_1$, $i_2$, $j_1$, $j_2$ ($1 \le i_1 \lt i_2 \le p$; $1 \le j_1 \lt j_2 \le q$), $A_{i_1, j_1} \oplus A_{i_1, j_2} \oplus A_{i_2, j_1} \oplus A_{i_2, j_2} = 0$, where $\oplus$ denotes the bitwise XOR operation.
翻译中…

There is a partially filled integer grid $G$ with $n$ rows and $m$ columns where only $k$ cells are filled. Polycarp wants to know how many ways he can assign integers to the unfilled cells so that the grid is beautiful.

翻译中…

However, Monocarp thinks that this problem is too easy. Therefore, he will perform $q$ updates on the grid. In each update, he will choose an unfilled cell and assign an integer to it. Note that these updates are persistent. That is, changes made to the grid will apply when processing future updates.

翻译中…

For each of the $q + 1$ states of the grid, the initial state and after each of the $q$ queries, determine the number of ways Polycarp can assign integers to the unfilled cells so that the grid is beautiful. Since this number can be very large, you are only required to output their values modulo $10^9+7$.

翻译中…

Input

翻译中…

The first line contains $t$ ($1 \le t \le 10^4$) — the number of test cases.

翻译中…

The first line of each test case contains four integers $n$, $m$, $k$ and $q$ ($2 \le n, m \le 10^5$; $0 \le k \le 10^5$; $q = 0$) — the number of rows, the number of columns, the number of fixed cells, and the number of updates.

翻译中…

The following $k$ lines contain three integers $r$, $c$ and $v$ ($1 \le r \le n, 1 \le c \le m$; $0 \le v \lt 2^{30}$) — indicating that $G_{r, c}$ is assigned the integer $v$.

翻译中…

The following $q$ lines contain three integers $r$, $c$ and $v$ ($1 \le r \le n, 1 \le c \le m$; $0 \le v \lt 2^{30}$) — indicating that $G_{r, c}$ is assigned the integer $v$.

翻译中…

It is guaranteed that the pairs $(r,c)$ over all assignments are distinct.

翻译中…

It is guaranteed that the sum of $n$, $m$, $k$ and $q$ over all test cases does not exceed $10^5$ respectively.

翻译中…

Output

翻译中…

For each test case, output $q + 1$ lines. The $i$-th line of output should contain the answer of the $i$-th state of the grid modulo $10^9 + 7$.

翻译中…

Note

翻译中…

In the first test case of the example, we have the following grid:

翻译中…

$0$$6$$10$$6$$0$$12$$10$$12$$?$

翻译中…

It can be proven that the only valid value for tile $(3, 3)$ is $0$.

翻译中…

样例

Input #1
2
3 3 8 0
2 1 6
3 2 12
1 2 6
2 2 0
1 3 10
1 1 0
2 3 12
3 1 10
2 5 2 0
1 1 10
1 2 30
Output #1
1
489373567
InputCopy OutputCopy
题目信息
题号
2022E1
时间限制
2 s
内存限制
512 MB
标签
2-SAT
二分
组合数学
构造
DFS 及类似
并查集
图论

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