C. Bear and Forgotten Tree 3
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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 nd 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 nd 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
Note

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

构造。

每次先以1为根构造深度为h的一支树杈1-2-3...h,如果h==d那么就在2下面接上1个节点 如果h!=d 那么就在1下面接上d-h个节点。

注意h==d的时候。2 1 1是有解的。

/* ***********************************************
Author :guanjun
Created Time :2016/3/29 9:49:51
File Name :cfvk1c.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 100010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
vector<int>v[maxn];
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n,d,h;
while(cin>>n>>d>>h){
if(d>h*){
puts("-1");continue;
}
int num=;
int vec,w;
if(d==h){
if(h==&&n>){
cout<<-<<endl;continue;
}
vec=,w=d-h+;
}
else vec=,w=d-h;
for(int i=;i<=h;i++){
v[num].push_back(num+);
num++;
}
for(int i=;i<=d-h;i++){
if(i==)v[vec].push_back(num+);
else v[num].push_back(num+);
num++;
//puts("-1");
}
//cout<<"num "<<num<<endl;
int mark=;
while(){
if(num==n)break;
for(int i=;i<=w;i++){
if(i==)v[vec].push_back(num+);
else v[num].push_back(num+);
num++;
if(num==n){
mark=;break;
}
}
if(mark)break;
}
for(int i=;i<=n;i++){
for(int j=;j<v[i].size();j++){
cout<<i<<" "<<v[i][j]<<endl;
}
}
}
return ;
}
C. Bear and Forgotten Tree 3
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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 nd 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 nd 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
Note

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

VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3的更多相关文章

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

  2. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths

    题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: ...

  3. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors

    题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...

  4. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths 构造

    D. Bear and Two Paths 题目连接: http://www.codeforces.com/contest/673/problem/D Description Bearland has ...

  5. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力

    C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has ...

  6. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题

    A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...

  7. VK Cup 2016 - Round 1 (Div. 2 Edition) E. Bear and Contribution 单调队列

    E. Bear and Contribution 题目连接: http://www.codeforces.com/contest/658/problem/E Description Codeforce ...

  8. VK Cup 2016 - Round 1 (Div. 2 Edition) D. Bear and Polynomials

    D. Bear and Polynomials 题目连接: http://www.codeforces.com/contest/658/problem/D Description Limak is a ...

  9. VK Cup 2016 - Round 1 (Div. 2 Edition) B. Bear and Displayed Friends 树状数组

    B. Bear and Displayed Friends 题目连接: http://www.codeforces.com/contest/658/problem/B Description Lima ...

随机推荐

  1. 【kmp+求所有公共前后缀长度】poj 2752 Seek the Name, Seek the Fame

    http://poj.org/problem?id=2752 [题意] 给定一个字符串,求这个字符串的所有公共前后缀的长度,按从小到达输出 [思路] 利用kmp的next数组,最后加上这个字符串本身 ...

  2. poj 2987 Firing

    Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 10696   Accepted: 3226 Descript ...

  3. NOIP 前夕 模板整理

    归并排序: #include<iostream> #include<cstdio> #include<cstring> using namespace std; ] ...

  4. angular中的this指向问题

    this是指向当前$scope的. 例如在ng-click的使用中,this是指向当前的$scope而并不是dom元素的. 我们可以使用this的一些方法和属性 我们打印一下this就会发现,this ...

  5. yii 之删除数据

    public function actionTest(){ //删除 //方法一 $result = Test::find()->where(['id' => 1])->all(); ...

  6. WEB学习-基础知识:列表、表单、div和span、注释、字符实体、HTML废弃标签介绍

    列表 无序列表 无序列表,用来表示一个列表的语义,并且每个项目和每个项目之间,是不分先后的. ul就是英语unordered list,“无序列表”的意思. li 就是英语list item , “列 ...

  7. Google代码风格配置文件(Java)(IDEA/Eclipse)

    官网:http://www.cnblogs.com/EasonJim/p/7837474.html 下载: 安装: IDEA/Eclipse导入相应文件即可. 说明: Google代码风格文件的缩进是 ...

  8. IntelliJ IDEA常用的快捷键(代码提示/注释代码/加入类注释和方法注释Javadoc)

    说明:IDEA的快捷键非常的多,但是下面这几种快捷键应该是最常用到的. 一.代码提示: [Ctrl]+[空格] 这个通常会与输入法开关冲突,解决方法是屏蔽输入法开关. 二.注释: 1.单行:[Ctrl ...

  9. iOS Application Security

    文章分A,B,C,D 4个部分. A) iOS Application Security 下面介绍iOS应用安全,如何分析和动态修改app. 1)iOS Application security Pa ...

  10. android 播放MP3

    <?xml version="1.0" encoding="utf-8"?> <!-- 定义当前布局的基本LinearLayout --> ...