問題一覧 > 通常問題

No.3585 Make Ends Meet (Easy)

レベル : / AI推定難易度 : 1100 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 42
作問者 : marc2825 / テスター : siganai
お気に入りにしたユーザー ProblemId : 13246 / 自分の提出
問題文最終更新日: 2026-08-29 00:42:59
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 504 (順位表) の他の問題:

Problem Statement

There is an undirected complete graph† with vertices $1,2,\dots,N$.
Remove exactly $M$ edges from this graph to create a new undirected graph $G$.
In the remaining graph $G$, you want the shortest distance (the number of edges traversed) from vertex $1$ to vertex $N$ to be exactly $K$‡.

If there is a way to remove edges that satisfies this condition, output Yes and $1$ such set of edges to remove.
If there is no such way, output No.


† An "undirected complete graph" is an undirected graph without self-loops or multiple edges in which there is exactly $1$ edge between any $2$ distinct vertices.
‡ If vertex $N$ cannot be reached from vertex $1$, the condition is considered not satisfied.

Constraints

  • $2 \leq N \leq 100$
  • $0 \leq M \leq \dfrac{N(N-1)}{2}$
  • $1 \leq K \leq N-1$
  • All input values are integers.

Input

The input is given from standard input in the following format.

$N\ M\ K$

Output

If there is no way to remove edges that satisfies the condition, output

No

.

If there is such a way, output in the format

Yes
$u_1\ v_1$
$u_2\ v_2$
$\vdots$
$u_M\ v_M$

.
Here, $(u_i,v_i)$ represents an edge to remove.
All edges must be distinct, and for each $i$, $1 \leq u_i,v_i \leq N$ and $u_i \neq v_i$ must hold.

If there are multiple valid outputs, any of them will be accepted.

Sample

Sample 1
Input
5 5 3
Output
Yes
1 3
1 4
1 5
2 5
4 5

For example, the path $1 \to 2 \to 3 \to 5$ of length $3$ is a shortest path, and no shorter path exists.

Sample 2
Input
4 2 3
Output
No

There is no way to remove edges that satisfies the condition.

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