CF755E.PolandBall and White-Red graph
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
PolandBall has an undirected simple graph consisting of n vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding some red edges. Then, he will add white edges in every remaining place. Therefore, the final graph will be a clique in two colors: white and red.
Colorfulness of the graph is a value min(d__r, d__w), where d__r is the diameter of the red subgraph and d__w is the diameter of white subgraph. The diameter of a graph is a largest value d such that shortest path between some pair of vertices in it is equal to d. If the graph is not connected, we consider its diameter to be -1.
PolandBall wants the final graph to be as neat as possible. He wants the final colorfulness to be equal to k. Can you help him and find any graph which satisfies PolandBall's requests?
PolandBall 拥有一个包含 n 个顶点的无向简单图。不幸的是,该图没有任何边,因此它非常悲伤。为了使图更快乐,PolandBall 决定添加若干条红色边;随后,他将在所有剩余未连通的顶点对之间添加白色边。因此,最终的图将是一个由白色和红色两种颜色构成的完全图(即任意两个顶点之间恰有一条边,且每条边被染为红色或白色)。
图的“色彩度”(colorfulness)定义为 min(dr,dw),其中 dr 是红色子图的直径,dw 是白色子图的直径。图的直径是指该图中某对顶点之间的最短路径长度所能取到的最大值 d;若图不连通,则其直径定义为 −1。
PolandBall 希望最终的图尽可能规整,即要求最终图的色彩度恰好等于 k。你能帮助他构造出任意一个满足 PolandBall 要求的图吗?
输入格式
The only one input line contains two integers n and k (2 ≤ n ≤ 1000, 1 ≤ k ≤ 1000), representing graph's size and sought colorfulness.
唯一的一行输入包含两个整数 n 和 k(2 ≤ n ≤ 1000,1 ≤ k ≤ 1000),分别表示图的大小和所求的“色彩丰富度”。
输出格式
If it's impossible to find a suitable graph, print -1.
Otherwise, you can output any graph which fulfills PolandBall's requirements. First, output m — the number of red edges in your graph. Then, you should output m lines, each containing two integers a__i and b__i, (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i) which means that there is an undirected red edge between vertices a__i and b__i. Every red edge should be printed exactly once, you can print the edges and the vertices of every edge in arbitrary order.
Remember that PolandBall's graph should remain simple, so no loops or multiple edges are allowed.
如果无法找到满足条件的图,请输出 -1。
否则,您可以输出任意一个满足 PolandBall 要求的图。首先,输出整数 m —— 即您所构造图中红色边的数量。随后,输出 m 行,每行包含两个整数 ai 和 bi(满足 1 ≤ ai, bi ≤ n 且 ai = bi),表示顶点 ai 与 bi 之间存在一条无向红色边。每条红色边必须恰好输出一次;边的输出顺序,以及每条边中两个顶点的输出顺序,均可任意。
请注意,PolandBall 的图必须保持为简单图,即不允许存在自环或重边。
输入输出样例
输入#1
4 1
输出#1
-1
输入#2
5 2
输出#2
4 1 2 2 3 3 4 4 5
说明/提示
In the first sample case, no graph can fulfill PolandBall's requirements.
In the second sample case, red graph is a path from 1 to 5. Its diameter is 4. However, white graph has diameter 2, because it consists of edges 1-3, 1-4, 1-5, 2-4, 2-5, 3-5.
在第一个样例中,不存在满足 PolandBall 要求的图。
在第二个样例中,红色图是一条从节点 1 到节点 5 的路径,其直径为 4。然而,白色图的直径为 2,因为它包含边 1-3、1-4、1-5、2-4、2-5 和 3-5。
输入解题思路,AI测评打分。不知道怎么写?