CF1644D.Cross Coloring

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a sheet of paper that can be represented with a grid of size n×mn \times m: nn rows and mm columns of cells. All cells are colored in white initially.

qq operations have been applied to the sheet. The ii-th of them can be described as follows:

  • xix_i yiy_i — choose one of kk non-white colors and color the entire row xix_i and the entire column yiy_i in it. The new color is applied to each cell, regardless of whether the cell was colored before the operation.

The sheet after applying all qq operations is called a coloring. Two colorings are different if there exists at least one cell that is colored in different colors.

How many different colorings are there? Print the number modulo 998 244 353998\,244\,353.

有一张可以表示为 n×mn \times m 网格的纸:共 nn 行、mm 列的单元格。初始时所有单元格均为白色。

对该纸张共执行了 qq 次操作。第 ii 次操作可描述如下:

  • xix_i yiy_i — 从 kk 种非白色颜色中任选一种,并将整行 xix_i 和整列 yiy_i 均染成该颜色。新颜色会覆盖每个单元格,无论该单元格在本次操作前是否已被染色。

执行完全部 qq 次操作后的纸张称为一种染色方案。若存在至少一个单元格在两种染色方案中被染成不同颜色,则称这两种染色方案不同。

问:共有多少种不同的染色方案?请输出结果对 998 244 353998\,244\,353 取模的值。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of testcases.

The first line of the testcase contains four integers n,m,kn, m, k and qq (1≤n,m,k,q≤2⋅1051 \le n, m, k, q \le 2 \cdot 10^5) — the size of the sheet, the number of non-white colors and the number of operations.

The ii-th of the following qq lines contains a description of the ii-th operation — two integers xix_i and yiy_i (1≤xi≤n1 \le x_i \le n; 1≤yi≤m1 \le y_i \le m) — the row and the column the operation is applied to.

The sum of qq over all testcases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

每个测试用例的第一行包含四个整数 n,m,kn, m, k 和 qq(1≤n,m,k,q≤2⋅1051 \le n, m, k, q \le 2 \cdot 10^5)——纸张的尺寸、非白色颜色种类数以及操作次数。

接下来的 qq 行中,第 ii 行描述第 ii 个操作——两个整数 xix_i 和 yiy_i(1≤xi≤n1 \le x_i \le n;1≤yi≤m1 \le y_i \le m)——表示该操作作用于第 xix_i 行、第 yiy_i 列。

所有测试用例中 qq 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each testcase, print a single integer — the number of different colorings modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一个整数——不同染色方案的数量对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    2
    1 1 3 2
    1 1
    1 1
    2 2 2 3
    2 1
    1 1
    2 2

    输出#1

    3
    4

输入解题思路,AI测评打分。不知道怎么写?

首页