题目链接:

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 题意: 给一棵树的节点数目n,直径d,最大深度h,问是否存在一棵树满足这些条件,存在的话任意输出一棵树;
比赛时先是被人hack,发现了一处错误改了后又交了一发,但最后还是挂在了system test上; 思路: 两种情况不存在树,一种是d>2*h,一种是d==1&&h==1&&n>2时;可以先生成最大深度的一条链,再在次基础上把最大直径的链生成;其余的都和最大深度的节点的父节点相连接就满足要求了; AC代码:
/*
2014300227 658C - 38 GNU C++11 Accepted 46 ms 2176 KB
*/ #include <bits/stdc++.h>
using namespace std;
int n,d,h;
int main()
{
scanf("%d%d%d",&n,&d,&h);
if(d>*h||(h==&&d==&&n>))cout<<"-1"<<"\n";
else
{
for(int i=;i<=h;i++)
{
printf("%d %d\n",i,i+);
}
if(d==h)
{
if(d<n-)
{
for(int i=h+;i<=n;i++)
{
printf("%d %d\n",h,i);
}
}
}
else
{ cout<<""<<" "<<h+<<"\n";
for(int i=h+;i<=d;i++)
{
printf("%d %d\n",i,i+);
}
for(int i=d+;i<=n;i++)
{
printf("%d %d\n",h,i);
} } } return ;
}

 

codeforces 658C C. Bear and Forgotten Tree 3(tree+乱搞)的更多相关文章

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

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

  2. Codeforces 193E - Fibonacci Number(打表找规律+乱搞)

    Codeforces 题目传送门 & 洛谷题目传送门 蠢蠢的我竟然第一眼想套通项公式?然鹅显然 \(5\) 在 \(\bmod 10^{13}\) 意义下并没有二次剩余--我真是活回去了... ...

  3. Codeforces Round #493 (Div. 2) C. Convert to Ones 乱搞_构造_好题

    题意: 给你一个长度为 nnn 的 010101串 ,你有两种操作: 1.将一个子串翻转,花费 XXX 2.将一个子串中的0变成1,1变成0,花费 YYY 求你将这个01串变成全是1的串的最少花费. ...

  4. Codeforces 1186F - Vus the Cossack and a Graph 模拟乱搞/欧拉回路

    题意:给你一张无向图,要求对这张图进行删边操作,要求删边之后的图的总边数 >= ceil((n + m) / 2), 每个点的度数 >= ceil(deg[i] / 2).(deg[i]是 ...

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

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

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

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

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

  9. Code Forces Bear and Forgotten Tree 3 639B

    B. Bear and Forgotten Tree 3 time limit per test2 seconds memory limit per test256 megabytes inputst ...

随机推荐

  1. HTTP头解读

    Http协议定义了很多与服务器交互的方法,最基本的有4种,分别是GET.POST.PUT.DELETE.一个URL地址用于描述一个网络上的资源, 而HTTP中的GET.POST.PUT. DELETE ...

  2. 软件工程第2次作业——Visual Studio 2017下基于C/C++的VSTS单元测试实践

    Write one minute, test all day long. 环境确定 IDE:Microsoft Visual Studio 2017 Community 语言:C++ 单元测试工具:V ...

  3. c# .net 我的Application_Error 全局异常抓取处理

    protected void Application_Error(object sender, EventArgs e)        {            //在出现未处理的错误时运行的代码   ...

  4. js jquery 插件

    $(function(){ (function($, document, undefiend){ $.fn.pagination = function(options){ var $this = $( ...

  5. HTML5,不仅仅是看上去非常美(第二弹:打造最美3D机房)

    前言 近期项目开发任务告一段落,刚好有时间整理这大半年的一些成果.使用html5时间还不久,对js的认识还不够深入.没办法,曾经一直搞java,对js的一些语言特性和概念一时还转换只是来. 上一篇第一 ...

  6. 设置Eclipse中properties文件打开方式myeclipse一样有source和properties两个视图方法

    东北大亨: 说明:如果想在eclipse的properties文件打开的方式出现source和properties视图就需要添加JBossTools插件 下面介绍如果添加插件: 1.打开官网 http ...

  7. 【BZOJ3544】[ONTAK2010]Creative Accounting 前缀和+set

    [BZOJ3544][ONTAK2010]Creative Accounting Description 给定一个长度为N的数组a和M,求一个区间[l,r],使得(\sum_{i=l}^{r}{a_i ...

  8. 在调用Response.End()时,会执行Thread.CurrentThread.Abort()操作

    在调用Response.End()时,会执行Thread.CurrentThread.Abort()操作. 如果将Response.End()放在try...catch中,catch会捕捉Thread ...

  9. 九度OJ 1073:杨辉三角形 (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3780 解决:1631 题目描述: 输入n值,使用递归函数,求杨辉三角形中各个位置上的值. 输入: 一个大于等于2的整型数n 输出: 题目可 ...

  10. 连通性 保证f具有介值性质