Everywhere is Sparser than Whole (Construction)

AtCoder
IDarc161_d
Time2000ms
Memory256MB
Difficulty
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 $N$ and $D$. Determine whether there is a simple undirected graph $G$ with $N$ vertices and $DN$ edges that satisfies the following condition. If it exists, find one such graph. **Condition:** Let $V$ be the vertex set of $G$. For any non-empty **proper** subset $X$ of $V$, the density of the induced subgraph of $G$ by $X$ is **strictly less than** $D$. What is an induced subgraph? For a vertex subset $X$ of graph $G$, the **induced subgraph** of $G$ by $X$ is the graph with vertex set $X$ and edge set containing all edges of $G$ that connect two vertices in $X$. In the above condition, note that we only consider vertex subsets that are neither empty nor the entire set. ## Constraints * $N \geq 1$ * $D \geq 1$ * $DN \leq 5 \times 10^4$ ## Input The input is given from Standard Input in the following format: $N$ $D$ [samples]
Samples
Input #1
3 1
Output #1
Yes
1 2
1 3
2 3

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

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

In all cases, the density of the induced subgraph is strictly less than $D = 1$, so this graph satisfies the condition.
Input #2
4 2
Output #2
No

A simple undirected graph with $4$ vertices and $8$ edges does not exist.
API Response (JSON)
{
  "problem": {
    "name": "Everywhere is Sparser than Whole (Construction)",
    "description": {
      "content": "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 $N$ and $D$. Determ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc161_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We define the **density** of a non-empty simple undirected graph as $\\displaystyle\\frac{(\\text{number\\ of\\ edges})}{(\\text{number\\ of\\ vertices})}$.\nYou are given positive integers $N$ and $D$. Determ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments