問題一覧 > 通常問題

No.1981 [Cherry 4th Tune N] An Example That Ruins the Algorithm

レベル : / AI推定難易度 : 1250 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 80
作問者 : 👑 Kazun / テスター : miscalc 👑 potato167
お気に入りにしたユーザー ProblemId : 4670 / 自分の提出
問題文最終更新日: 2022-06-17 20:23:01
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 348 Early Summer Rain (順位表) の他の問題:

Problem Statement

You are given non-negative integers $N,K$. Does there exist a graph satisfying all of the following conditions? If one exists, find an example and output it as described in the Output section. If none exists, report that fact.

  • The number of vertices is $2N$. These $2N$ vertices are denoted by $X_1, X_2, \dots, X_N, Y_1, Y_2, \dots, Y_N$.
  • Let $M$ be the number of edges. The $i~(1 \leq i \leq M)$-th edge is an undirected edge connecting $X_{a_i}$ and $Y_{b_i}$.
  • The graph is a simple graph. That is, for $1 \leq i \leq M, 1 \leq j \leq M$, if $i \neq j$, then $(a_i, b_i) \neq (a_j, b_j)$.
  • A perfect matching exists.
  • The size of the matching obtained by running Algorithm A, described below, is $K$ (here, the size of a matching is the number of edges forming the matching).

アルゴリズム A
$2N$ 個の頂点全てを白で塗る.
$i=1,2, \dots, M$ の順に以下を行う.
    2つの頂点 $X_{a_i}, Y_{b_i}$ が共に白で塗られているならば, $i$ 番目の辺を採用し, 頂点 $X_{a_i}, Y_{b_i}$ を赤で塗り替える.
    そうでない場合, $i$ 番目の辺は採用しない.
採用した辺たちからなるマッチングを出力する.

Constraints

  • $1 \leq N \leq 500$
  • $0 \leq K \leq N$
  • All input values are integers.

Input

$N$ $K$

Output

If no graph satisfying the conditions exists, output -1 on a single line.

If one exists, output it in the following format.

$M$
$a_1$ $b_1$
$\vdots$
$a_M$ $b_M$

If there are multiple graphs satisfying the conditions, you may output any one of them.

In either case, do not forget the newline at the end.

Sample

Sample 1
Input
3 2
Output
4
1 3
2 3
3 1
1 2

The graph given by this output corresponds to the one below. Running Algorithm A on this graph proceeds as follows.

  • Let $i=1$. Here, vertices $X_1, Y_3$ are both white, so the $1$-st edge is adopted. Then, vertices $X_1, Y_3$ are painted red.
  • Let $i=2$. Here, vertex $Y_3$ is red, so the $2$-nd edge is not adopted.
  • Let $i=3$. Here, vertices $X_3, Y_1$ are both white, so the $3$-rd edge is adopted. Then, vertices $X_3, Y_1$ are painted red.
  • Let $i=4$. Here, vertex $X_1$ is red, so the $4$-th edge is not adopted.
Therefore, the edges numbered $1,3$ are adopted, and a matching of size $2$ is output.

Sample 2
Input
46 0
Output
-1

When running Algorithm A, the edge at $i=1$ is always adopted. Hence, the size of the output matching can never be $0$.

Sample 3
Input
4 4
Output
16
2 1
1 1
1 3
4 3
2 4
4 2
3 3
1 2
3 4
2 2
4 1
4 4
1 4
2 3
3 1
3 2

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。