AtCoder Regular Contest 176 (Sponsored by Mynavi)
A
01 Matrix Again
AtCoder
⌀ 1346
原题
←B →
翻译中…

Problem Statement

翻译中…

There is an $N \times N$ grid. Let $(i, j)$ denote the cell at the $i$-th row from the top and the $j$-th column from the left.

翻译中…

You are to fill each cell with $0$ or $1$. Construct one method to fill the grid that satisfies all of the following conditions:

翻译中…
  • The cells $(A_1,B_1), (A_2,B_2), \dots, (A_M,B_M)$ contain $1$.
  • The integers in the $i$-th row sum to $M$. $(1 \le i \le N)$
  • The integers in the $i$-th column sum to $M$. $(1 \le i \le N)$
翻译中…

It can be proved that under the constraints of this problem, there is at least one method to fill the grid that satisfies the conditions.

翻译中…

Constraints

翻译中…
  • $1 \le N \le 10^5$
  • $1 \le M \le \min(N,10)$
  • $1 \le A_i, B_i \le N$
  • $(A_i, B_i) \neq (A_j, B_j)$ if $i \neq j$.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M
A_1 B_1
A_2 B_2
\vdots
A_{M} B_{M}

翻译中…

Output

翻译中…

Let $(x_1,y_1), (x_2,y_2), \dots, (x_k,y_k)$ be the cells that contain $1$, and print the following:

翻译中…

k
x_1 y_1
x_2 y_2
\vdots
x_k y_k

翻译中…

If multiple methods satisfy the conditions, any of them will be considered correct.

翻译中…

样例

Input #1
4 2
1 4
3 2
Output #1
8
1 2
1 4
2 1
2 4
3 2
3 3
4 1
4 3
This output fills the grid as follows. All the conditions are satisfied, so this output is correct.
Input #2
3 3
3 1
2 3
1 3
Output #2
9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Input #3
7 3
1 7
7 6
6 1
Output #3
21
1 6
2 4
4 1
7 3
3 6
4 5
6 1
1 7
7 6
3 5
2 2
6 3
6 7
5 4
5 2
2 5
5 3
1 4
7 1
4 7
3 2
题目信息
题号
arc176_a
时间限制
4 s
内存限制
1024 MB

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