B. Bear and Forgotten Tree 3

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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”.

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 vertex 1, 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.

Examples

input

5 3 2

output

1 2

1 3

3 4

3 5

input

8 5 2

output

-1

input

8 4 2

output

4 8

5 7

2 3

8 1

2 1

5 6

1 5

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> using namespace std;
#define MAX 150000
int n,d,h;
int v[MAX+5];
int tag[MAX+5];
int main()
{
scanf("%d%d%d",&n,&d,&h);
if(d>2*h||d<h||(d==1&&h==1&&n!=2))
{printf("-1\n");return 0;}
int i;
memset(v,-1,sizeof(v));
memset(tag,0,sizeof(tag));
for( i=1;i<=h;i++)
{
v[i]=i+1;
tag[i]=1;tag[i+1]=1;
cout<<i<<" "<<v[i]<<endl;
}
if(d-h>0)
{
v[1]=i-1+2;
cout<<1<<" "<<v[1]<<endl;
tag[i-1+2]=1;
} for(int j=i+2-1;j<d-h-1+i+2-1;j++)
{
v[j]=j+1;
cout<<j<<" "<<v[j]<<endl;
tag[j]=1;tag[j+1]=1;
}
int num;
if(h==1)
num=1;
else
num=2;
for(int j=1;j<=n;j++)
{
if(tag[j]==0)
{
cout<<num<<" "<<j<<endl;
}
}
return 0; }

Code Forces Bear and Forgotten Tree 3 639B的更多相关文章

  1. Codeforces 639B——Bear and Forgotten Tree 3——————【构造、树】

    Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  2. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E - Bear and Forgotten Tree 2 链表

    E - Bear and Forgotten Tree 2 思路:先不考虑1这个点,求有多少个连通块,每个连通块里有多少个点能和1连,这样就能确定1的度数的上下界. 求连通块用链表维护. #inclu ...

  3. VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3 构造

    C. Bear and Forgotten Tree 3 题目连接: http://www.codeforces.com/contest/658/problem/C Description A tre ...

  4. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E. Bear and Forgotten Tree 2 bfs set 反图的生成树

    E. Bear and Forgotten Tree 2 题目连接: http://www.codeforces.com/contest/653/problem/E Description A tre ...

  5. codeforces 658C C. Bear and Forgotten Tree 3(tree+乱搞)

    题目链接: C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes ...

  6. VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3

    C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. [Codeforces 639B] Bear and Forgotten Tree 3

    [题目链接] https://codeforces.com/problemset/problem/639/B [算法] 当d > n - 1或h > n - 1时 , 无解 当2h < ...

  8. 【Codeforces 639B】Bear and Forgotten Tree 3

    [链接] 我是链接,点我呀:) [题意] [题解] 首先,因为高度是h 所以肯定1下面有连续的h个点依次连成一条链.->用了h+1个点了 然后,考虑d这个约束. 会发现,形成d的这个路径,它一定 ...

  9. CodeForces 658C Bear and Forgotten Tree 3 (构造)

    题意:构造出一个 n 个结点,直径为 m,高度为 h 的树. 析:先构造高度,然后再构造直径,都全了,多余的边放到叶子上,注意直径为1的情况. 代码如下: #pragma comment(linker ...

随机推荐

  1. Android Shape 形状

    Shape继承体系: Shape (android.graphics.drawable.shapes) ----PathShape (android.graphics.drawable.shapes) ...

  2. 信号处理函数(3)-sigaction() 为信号注册信号捕捉函数

    定义: int sigaction(int signum,const struct sigaction *act ,struct sigaction *oldact); 表头文件: #include& ...

  3. eclipse配置 嵌入式-基于linux

    Eclipse可以安装在各种操作系统.这里是安装到Ubuntu 10.10上.有两种方法实现安装,一是采用Ubuntu的软件源:二是从官方下载后解压. 1.  通过Ubuntu软件源安装 $ sudo ...

  4. 关于HashMap初始化容量问题

    使用阿里云代码规范插件扫描后出现以下提示: hashmap should set a size when initalizing,即hashmap应该在初始化时设置一个大小 在网上搜到一篇讲解(htt ...

  5. 【转】搞清楚LzoCodec和LzopCodec

    使用LZO过程会发现它有两种压缩编码可以使用,即LzoCodec和LzopCodec,下面说说它们区别: LzoCodec比LzopCodec更快, LzopCodec为了兼容LZOP程序添加了如 b ...

  6. Eclipse “cannot be resolved to a type” error

    引言:     eclipse新导入的项目经常可以看到"XX cannot be resolved to a type"的报错信息.本文将做以简单总结. 正文:     (1)jd ...

  7. 【转载】PHP 常用的header头部定义汇总

    header() 函数向客户端发送原始的 HTTP 报头. 认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数(在 PHP 4 以及更高的版本中,您可以使用输出缓存来解决此 ...

  8. HTML5标准最终来了,看什么书学习最好??????

    近期看了一本书<HTML5网页开发实例具体解释>,是大众点评的攻城狮写的,认为非常有收获.看样子眼下大多数的国内网页都支持HTML5了,全栈project师是不是必须得会HTML5? 有兴 ...

  9. 回文树(回文自动机) - BZOJ 3676 回文串

    BZOJ 3676 回文串 Problem's Link: http://www.lydsy.com/JudgeOnline/problem.php?id=3676 Mean: 略 analyse: ...

  10. http常见的5个错误

    1. HTTP 500错误(内部服务器错误)对对HTTP 500错误的定义已经充分证明了这是一个最常见的HTTP错误. 一般来说,HTTP 500 错误就是web服务器发生内部错误时返回的信息. 例如 ...