CF639B.Bear and Forgotten Tree 3

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered 1 through n.

Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only three values n, d and h:

  • The tree had exactly n vertices.
  • The tree had diameter d. In other words, d was the biggest distance between two vertices.
  • Limak also remembers that he once rooted the tree in vertex 1 and after that its height was h. In other words, h was the biggest distance between vertex 1 and some other vertex.

The distance between two vertices of the tree is the number of edges on the simple path between them.

Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1".

树是一个由 nn 个顶点和 n−1n-1 条边构成的连通无向图。顶点编号为 11 到 nn。

Limak 是一只小北极熊,Radewoosh 是他的宿敌。Limak 曾经拥有一棵树,但被 Radewoosh 偷走了。熊现在非常难过,因为他对这棵树几乎毫无印象——他只能告诉你三个数值 nn、dd 和 hh:

  • 这棵树恰好有 nn 个顶点;
  • 这棵树的直径为 dd,即任意两个顶点之间距离的最大值为 dd;
  • Limak 还记得他曾将该树以顶点 11 为根进行有根化,此时树的高度为 hh,即顶点 11 到其余任意顶点的距离的最大值为 hh。

树中两个顶点之间的距离定义为连接它们的简单路径上的边数。

请帮助 Limak 恢复他的树。请判断是否存在满足上述条件的树;若存在,请构造出任意一棵满足条件的树,并以任意顺序输出其所有边;也有可能 Limak 记错了,此时不存在满足条件的树——在这种情况下,请输出 -1。

输入格式

The first line contains three integers n, d and h (2 ≤ n ≤ 100 000, 1 ≤ h ≤ d ≤ n - 1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively.

第一行包含三个整数 nn、dd 和 hh(2 ≤ n ≤ 100 0002 \leq n \leq 100\,000,1 ≤ h ≤ d ≤ n − 11 \leq h \leq d \leq n - 1),分别表示顶点数、直径,以及以顶点 1 为根时的树高。

输出格式

If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes).

Otherwise, describe any tree matching Limak's description. Print n - 1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order.

如果不存在符合林姆克记忆的树,则输出唯一一行 “-1”(不带引号)。

否则,请描述任意一棵符合林姆克描述的树。输出 n−1n-1 行,每行包含两个以空格分隔的整数——即该边所连接的两个顶点的编号。若存在多棵合法的树,输出其中任意一棵即可。边的输出顺序可以任意。

输入输出样例

  • 输入#1

    5 3 2

    输出#1

    1 2
    1 3
    3 4
    3 5
  • 输入#2

    8 5 2

    输出#2

    -1
  • 输入#3

    8 4 2

    输出#3

    4 8
    5 7
    2 3
    8 1
    2 1
    5 6
    1 5

说明/提示

Below you can see trees printed to the output in the first sample and the third sample.

下面你可以看到第一个样例和第三个样例中输出的树。

输入解题思路,AI测评打分。不知道怎么写?

首页