atcoder#ARC161D. [ARC161D] Everywhere is Sparser than Whole (Construction)

[ARC161D] Everywhere is Sparser than Whole (Construction)

Score : 500500 points

Problem Statement

We define the density of a non-empty simple undirected graph as $\displaystyle\frac{(\text{number\ of\ edges})}{(\text{number\ of\ vertices})}$.

You are given positive integers NN and DD. Determine whether there is a simple undirected graph GG with NN vertices and DNDN edges that satisfies the following condition. If it exists, find one such graph.

Condition: Let VV be the vertex set of GG. For any non-empty proper subset XX of VV, the density of the induced subgraph of GG by XX is strictly less than DD.

What is an induced subgraph?

For a vertex subset XX of graph GG, the induced subgraph of GG by XX is the graph with vertex set XX and edge set containing all edges of GG that connect two vertices in XX. In the above condition, note that we only consider vertex subsets that are neither empty nor the entire set.

Constraints

  • N1N \geq 1
  • D1D \geq 1
  • DN5×104DN \leq 5 \times 10^4

Input

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

NN DD

Output

If there is a simple undirected graph that satisfies the condition, print Yes; otherwise, print No. Furthermore, in the case of Yes, print a graph that satisfies the condition in the following format in the next DNDN lines. If multiple graphs satisfy the condition, any of them will be considered correct.

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ADNA_{DN} BDNB_{DN}

  • 1Ai,BiN  (1iDN)1 \leq A_i, B_i \leq N \ \ (1 \leq i \leq DN)
  • AiBi  (1iDN)A_i \neq B_i \ \ (1 \leq i \leq DN)
  • $\{A_i, B_i\} \neq \{A_j, B_j\} \ \ (1 \leq i < j \leq DN)$
  • The vertices of the graph are numbered from 11 to NN.
  • The ii-th line of the output represents that the ii-th edge connects vertex AiA_i and vertex BiB_i.
  • The order of the edges (which edge is printed first) and the order of the vertices (which endpoint of each edge is printed first) may be arbitrary.
3 1
Yes
1 2
1 3
2 3

The printed graph has vertex set {1,2,3}\{1, 2, 3\} and edge set {(1,2),(1,3),(2,3)}\{(1, 2), (1, 3), (2, 3)\}, and is simple. The vertex set XX has 66 non-empty proper subsets: {1},{2},{3},{1,2},{1,3},{2,3}\{1\}, \{2\}, \{3\}, \{1, 2\}, \{1, 3\}, \{2, 3\}.

  • For X={1},{2},{3}X = \{1\}, \{2\}, \{3\}, the edge sets of the induced subgraphs by XX are empty, and the densities are 01=0\displaystyle\frac{0}{1} = 0.
  • For X={1,2},{1,3},{2,3}X = \{1, 2\}, \{1, 3\}, \{2, 3\}, the edge sets of the induced subgraphs by XX are {(1,2)},{(1,3)},{(2,3)}\{(1, 2)\}, \{(1, 3)\}, \{(2, 3)\}, respectively, and the densities are all 12\displaystyle\frac{1}{2}.

In all cases, the density of the induced subgraph is strictly less than D=1D = 1, so this graph satisfies the condition.

4 2
No

A simple undirected graph with 44 vertices and 88 edges does not exist.