第 1120 场 Codeforces Round(Div. 1)
F
Rank Removal
Codeforces
3500
原题
← E→
翻译中…

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

翻译中…

On a move, let $r$ be the rank of the current matrix $M$. Farmer John must choose exactly $r$ distinct entries of $M$ that are equal to $1$ and change all of them to $0$.

翻译中…

Farmer John wants to turn $M$ 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.

翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

Each of the next $m$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i,y_i \le n$), denoting that $M_{x_i,y_i}=1$.

翻译中…

All other entries of $M$ are equal to $0$.

翻译中…

It is guaranteed that all given cells are distinct.

翻译中…

It is guaranteed that the rank of $M$ over $\mathbb{F}_2$ is $n$ for every test case.

翻译中…

It is guaranteed that the sum of $m$ over all test cases does not exceed $300^2$.

翻译中…

Output

翻译中…

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

翻译中…

Then output $k$ lines, each describing one move.

翻译中…

For each move, let $r$ be the rank of the current matrix before the move. Output the integer $r$ on a new line. Then, output $r$ pairs of integers $x_i$ and $y_i$ representing the cells of a matrix we are changing to $0$.

翻译中…

For every $1 \le i \le r$, the cell $(x_i,y_i)$ must contain a $1$ 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.

翻译中…

Note

翻译中…

For the first test case, the matrix is

翻译中…

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

翻译中…

Its rank is $2$, so we remove the two entries $(1,1)$ and $(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 $3$. After removing $(1,2)$, $(2,3)$, and $(3,3)$, the matrix becomes

翻译中…

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

翻译中…

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

翻译中…

样例

Input #1
2
2 2
1 1
2 2
3 5
1 1
1 2
2 2
2 3
3 3
Output #1
1
2
1 1
2 2
2
3
1 2
2 3
3 3
2
1 1
2 2
InputCopy OutputCopy
题目信息
题号
2262F
时间限制
2 s
内存限制
256 MB
标签
数学

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