AtCoder Beginner Contest 131
翻译中…
Problem Statement
翻译中…
Does there exist an undirected graph with $N$ vertices satisfying the following conditions?
翻译中…
- The graph is simple and connected.
- The vertices are numbered
$1, 2, ..., N$. - Let
$M$be the number of edges in the graph. The edges are numbered$1, 2, ..., M$, the length of each edge is$1$, and Edge$i$connects Vertex$u_i$and Vertex$v_i$. - There are exactly
$K$pairs of vertices$(i,\ j)\ (i < j)$such that the shortest distance between them is$2$.
翻译中…
If there exists such a graph, construct an example.
翻译中…
Constraints
翻译中…
- All values in input are integers.
$2 \leq N \leq 100$$0 \leq K \leq \frac{N(N - 1)}{2}$
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N K
翻译中…
Output
翻译中…
If there does not exist an undirected graph with $N$ vertices satisfying the conditions, print -1.
翻译中…
If there exists such a graph, print an example in the following format (refer to Problem Statement for what the symbols stand for):
翻译中…
M
u_1 v_1
:
u_M v_M
翻译中…
If there exist multiple graphs satisfying the conditions, any of them will be accepted.
翻译中…
样例
Input #1
5 3
Output #1
5
4 3
1 2
3 1
4 5
2 3
This graph has three pairs of vertices such that the shortest distance between them is $2$: $(1,\ 4)$, $(2,\ 4)$, and $(3,\ 5)$. Thus, the condition is satisfied.
Input #2
5 8
Output #2
-1
There is no graph satisfying the conditions.
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。