CF2262F.Rank Removal

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Farmer John is playing a game involving an n×nn \times n binary matrix MM. Throughout this problem, all matrix \href\href{https://en.wikipedia.org/wiki/Rank_(linear_algebra)}{\text{ranks}} are computed over the field F2\mathbb{F}_2. Initially, the rank of MM is guaranteed to be nn.

On a move, let rr be the rank of the current matrix MM. Farmer John must choose exactly rr distinct entries of MM that are equal to 11 and change all of them to 00.

Farmer John wants to turn MM into the zero matrix using the minimum possible number of moves.

For each test case, output the minimum number of moves and any sequence of moves that achieves it.

农夫约翰正在玩一个涉及 n×nn \times n 二进制矩阵 MM 的游戏。在本题中,所有矩阵的 \href\href{https://en.wikipedia.org/wiki/Rank_(linear_algebra)}{\text{秩}} 均在域 F2\mathbb{F}_2 上计算。初始时,矩阵 MM 的秩保证为 nn。

在一次操作中,设当前矩阵 MM 的秩为 rr。农夫约翰必须恰好选择 MM 中 rr 个互不相同的值为 11 的元素,并将它们全部变为 00。

农夫约翰希望以最少的操作次数将 MM 变为零矩阵。

对每个测试用例,输出最少操作次数,以及任意一个达到该次数的操作序列。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (2≤n≤300,n≤m≤n22 \le n \le 300, n \le m \le n^2) — the size of the matrix and the number of entries equal to 11.

Each of the next mm lines contains two integers xix_i and yiy_i (1≤xi,yi≤n1 \le x_i,y_i \le n), denoting that Mxi,yi=1M_{x_i,y_i}=1.

All other entries of MM are equal to 00.

It is guaranteed that all given cells are distinct.

It is guaranteed that the rank of MM over F2\mathbb{F}_2 is nn for every test case.

It is guaranteed that the sum of mm over all test cases does not exceed 3002300^2.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n≤3002 \le n \le 300,n≤m≤n2n \le m \le n^2),分别表示矩阵的大小以及值为 11 的元素个数。

接下来的 mm 行中,每行包含两个整数 xix_i 和 yiy_i(1≤xi,yi≤n1 \le x_i, y_i \le n),表示 Mxi,yi=1M_{x_i,y_i} = 1。

矩阵 MM 中其余所有元素均为 00。

保证所有给定的单元格互不相同。

保证对于每个测试用例,矩阵 MM 在 F2\mathbb{F}_2 上的秩均为 nn。

保证所有测试用例的 mm 值之和不超过 3002300^2。

输出格式

For each test case, first output an integer kk — the minimum number of moves needed to turn MM into the zero matrix.

Then output kk lines, each describing one move.

For each move, let rr be the rank of the current matrix before the move. Output the integer rr on a new line. Then, output rr pairs of integers xix_i and yiy_i representing the cells of a matrix we are changing to 00.

For every 1≤i≤r1 \le i \le r, the cell (xi,yi)(x_i,y_i) must contain a 11 in the current matrix before the move. All chosen cells in the same move must be distinct.

If there are multiple optimal sequences of moves, you may output any of them.

对于每个测试用例,首先输出一个整数 kk —— 将矩阵 MM 变为零矩阵所需的最少移动次数。

然后输出 kk 行,每行描述一次移动。

对于每次移动,设 rr 为本次移动前当前矩阵的秩。在新的一行中输出整数 rr;接着输出 rr 对整数 xix_i 和 yiy_i,表示本次移动中被置为 00 的矩阵单元格坐标。

对每个 1≤i≤r1 \le i \le r,单元格 (xi,yi)(x_i,y_i) 在本次移动前的当前矩阵中必须为 11。同一次移动中所选的所有单元格必须互不相同。

若存在多个最优移动序列,可输出其中任意一个。

输入输出样例

  • 输入#1

    2
    2 2
    1 1
    2 2
    3 5
    1 1
    1 2
    2 2
    2 3
    3 3

    输出#1

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

说明/提示

For the first test case, the matrix is

\\left\[ \\begin{array}{cc} 1 & 0 \\\\ 0 & 1 \\end{array} \\right\].

Its rank is 22, so we remove the two entries (1,1)(1,1) and (2,2)(2,2) in one move.

For the second test case, the initial matrix is

\\left\[ \\begin{array}{ccc} 1 & 1 & 0 \\\\ 0 & 1 & 1 \\\\ 0 & 0 & 1 \\end{array} \\right\].

Its rank is 33. After removing (1,2)(1,2), (2,3)(2,3), and (3,3)(3,3), the matrix becomes

\\left\[ \\begin{array}{ccc} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 0 \\end{array} \\right\],

which has rank 22. We then remove (1,1)(1,1) and (2,2)(2,2) in the second move.

对于第一个测试用例,矩阵为

[1001].\left[ \begin{array}{cc} 1 & 0 \\ 0 & 1 \end{array} \right].

其秩为 22,因此我们在一次操作中移除两个元素 (1,1)(1,1) 和 (2,2)(2,2)。

对于第二个测试用例,初始矩阵为

[110011001].\left[ \begin{array}{ccc} 1 & 1 & 0 \\ 0 & 1 & 1 \\ 0 & 0 & 1 \end{array} \right].

其秩为 33。在移除 (1,2)(1,2)、(2,3)(2,3) 和 (3,3)(3,3) 后,矩阵变为

[100010000],\left[ \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 0 \end{array} \right],

其秩为 22。随后我们在第二次操作中移除 (1,1)(1,1) 和 (2,2)(2,2)。

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

首页