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. Jerasure库接口简介及性能测试

    http://blog.chinaunix.net/uid-20196318-id-3277600.html Jerasure库提供Reed-Solomon和Cauchy Reed-Solomon两种 ...

  2. 多线程-java并发编程实战笔记

    线程安全性 编写线程安全的代码实质上就是管理对状态的访问,而且通常都是共享的,可变的状态. 一个对象的状态就是他的数据,存储在状态变量中,比如实例域或静态域.所谓共享是指一个对象可以被多个线程访问:所 ...

  3. 【BZOJ2002】弹飞绵羊(LCT)

    题意:给定一棵树,要求维护以下操作: 1.删除连接(x,y)的边 2.将(x,y)之间连边 3.询问某点子树大小 对于100%的数据n<=200000,m<=100000 思路:第一道有加 ...

  4. eq=等于gt=大于lt=小于的英文全称

    EQ: Equal GT: Greater Than LT: Less than 知道全称就不会忘记

  5. npm start 修改启动端口的不同方式

    antd的启动配置文件基于package.json文件,配合roadhog使用时,启动配置是: "scripts": { "start": "road ...

  6. 王垠 :写给支持和反对《完全用Linux工作》的人们 ( 2004/8/26)

    在一阵阵唾骂和欢呼声中,<完全用linux工作>被转载到了天涯海角.很多人支持我,也有很多人唾骂我.我不知道它是怎样流传到那么多地方,其实 我不知道它都被转到哪里去了…… 我知道现在这篇文 ...

  7. 10.Java web—JavaBean

    定义一个类,然后在jsp页面通过<jsp:useBean>标签调用 重点是类属性名要起得规则,一般是setXXX  getXXXX 新建一个类UserInfo public class U ...

  8. 关于button中设置文字不显示的问题

    这个因为使用的image加载方式是setimage而不是setbackgroundimage导致文字始终出不来.

  9. 【面试 hibernate】【第二篇】hibernate相关问题

    1.hibernate工作原理[说一下你怎么理解的hibernate] hibernate是一个ORM对象关系映射的持久层框架,是对JDBC的轻量级封装. [可以不记,hibernate核心接口] 1 ...

  10. [React] Persist Form Data in React and Formik with formik-persist

    It can be incredibly frustrating to spend a few minutes filling out a form only to accidentally lose ...