CodeForces-657A-Bear and Forgotten Tree 3

来源:互联网 发布:师洋淘宝店东西能用吗 编辑:程序博客网 时间:2024/05/04 07:44

Description

A tree is a connected undirected graph consisting of n vertices andn  -  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 valuesn, d andh:

  • 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".

Input

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 vertex1, respectively.

Output

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.

Sample Input

Input
5 3 2
Output
1 21 33 43 5
Input
8 5 2
Output
-1
Input
8 4 2
Output
4 85 72 38 12 15 61 5

我的做法是以高度构造一条链,然后往里面根据直径来加结点。


h不可能大于d,而且d也不可能大于2h。

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int main(){    int n,d,h;    while(scanf("%d%d%d",&n,&d,&h)!=EOF)    {        if(h>d) { printf("-1\n"); continue; }        if(d>2*h||(h==1&&d==1&&n>2)){ printf("-1\n"); continue; }        else        {            int dep=h,t=1;            while(dep--)            {                printf("%d %d\n",t,t+1);                d--;                t++;            }            int w=1;            if(d==0)            {                while(t!=n)                {                    printf("2 %d\n",t+1);                    t++;                }            }            else            {                while(d--)                {                    printf("%d %d\n",w,t+1);                    w=t+1;                    t++;                }                 while(t!=n) {            printf("%d %d\n",1,t+1);            t++;            }        }    }}return 0;}

0 0