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. iOS7 Xcode 5如何设置隐藏状态栏

    转自:http://www.cocoachina.com/ask/questions/show/99658 最简单直接的方法: 直接在RootViewController.mm里面(Cocos2d-x ...

  2. java中==和equals和hashcode的区别详解

    一.相同点 都是用来进行值或对象的比较. 二.不同点 对于“==”而言,对于基本类型(char,byte,short,int,long,float,double,boolean),对比的是值,所以是相 ...

  3. Django教程:[33]从数据库生成模型

    在使用django做网站的时候,有时候我们的数据库来自一个已有的数据库,如何整合这个数据库呢? django提供了方便的方法来整合已有数据库,下面我们看看具体的方法: 1.先来设置数据库:在网站文件夹 ...

  4. FreeRTOS 任务优先级分配方案

    任务优先级说明下面对 FreeRTOS 优先级相关的几个重要知识点进行下说明,这些知识点在以后的使用中务必要掌握牢固.  FreeRTOS 中任务的最高优先级是通过 FreeRTOSConfig.h ...

  5. iframe中子父窗口互调的js方法

    转载自:http://www.cnblogs.com/chinafine/archive/2011/09/15/2177746.html 一.父窗口调用iframe子窗口方法 1.HTML语法:< ...

  6. 框架Iframe的退出,IE 火狐都没问题 到360就不跳转页面 刷新一遍才跳转到登录页

    遇到这种情况 ,郁闷死了,来回折腾好几种跳转方法,最后有一个灵感,当我点击退出按钮的时候,我是用jquery $("#ID").click(function(){}) 这种方法异步 ...

  7. http://jadethao.iteye.com/blog/1926525

    http://jadethao.iteye.com/blog/1926525 ————————————————————————————————————————————————————————————— ...

  8. CI 多表关联查询

    方法一:$this->db->query("sql  语句");     直接写sql语句 方法二: #多表关联查询 $data=$this->db->fr ...

  9. 后台登陆功能的实现 SESSION

    控制器 <?php // 本类由系统自动生成,仅供测试用途 class IndexAction extends Action { public function index(){ $this-& ...

  10. 一个 Map 函数、一个 Reduce 函数和一个 main 函数

    MapReduce 最简单的 MapReduce应用程序至少包含 3 个部分:一个 Map 函数.一个 Reduce 函数和一个 main 函数.main 函数将作业控制和文件输入/输出结合起来.在这 ...