[题目链接]

https://codeforces.com/problemset/problem/639/B

[算法]

当d > n - 1或h > n - 1时 , 无解

当2h < d时无解

当d = 1 , n不为2时 , 无解

否则 , 我们先构造一条长度为h的链 , 然后 , 将一条(d - h)的链接到根上 , 再将剩余节点接到根上

时间复杂度 : O(N)

[代码]

#include<bits/stdc++.h>
using namespace std; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} int main()
{ int n , h , d;
read(n); read(d); read(h);
if (d > n - || h > n - )
{
printf("-1\n");
return ;
}
if (h * < d)
{
printf("-1\n");
return ;
}
if (d == && n != )
{
printf("-1\n");
return ;
}
for (int i = ; i <= h + ; i++) printf("%d %d\n",i,i - );
for (int i = ; i <= d - h; i++)
{
if (i == ) printf("%d %d\n",,h + + i);
else printf("%d %d\n",h + i,h + + i);
}
if (d == h)
{
for (int i = d + ; i <= n; i++)
printf("%d %d\n",,i);
} else
{
for (int i = d + ; i <= n; i++)
printf("%d %d\n",,i);
} return ; }

[Codeforces 639B] Bear and Forgotten Tree 3的更多相关文章

  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. Codeforces 658C Bear and Forgotten Tree 3【构造】

    题目链接: http://codeforces.com/contest/658/problem/C 题意: 给定结点数,树的直径(两点的最长距离),树的高度(1号结点距离其他结点的最长距离),写出树边 ...

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

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

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

  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 题目连接: 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. 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 ...

随机推荐

  1. 第二次 Ubuntu16.04 vi编辑器的方向键和退格问题

    新安装ubuntu后,好多人可能都碰到过这样的问题,vi对文件进行编辑时,上下左右键变成了ABDC,退格键也不管用. 解决办法其实也很简单,首先卸载掉旧的vim-common. apt-get rem ...

  2. Wireshark does not show SSL/TLS

    why it doesn't show as "TLS/SSL"? Because it's not on the standard port for SSL/TLS. You c ...

  3. 当java web项目部署到服务器上时,无法将图片等媒体文件保存到服务器的最终奥义

    今天,我在部署web项目至云服务器上(Tomcat8.0)时,突然发现我的应用,无法上传图片,视频等多媒体文件了,一再检查自己的代码逻辑没有问题之后,逐一排查,首先想到的就是看一下控制台打印的日志,日 ...

  4. Unix网络编程 — 头文件解析

    1.1. < sys/types.h > primitive system data types(包含很多类型重定义,如pid_t.int8_t等) 1.2. < sys/socke ...

  5. 17-看图理解数据结构与算法系列(NoSQL存储-LSM树)

    关于LSM树 LSM树,即日志结构合并树(Log-Structured Merge-Tree).其实它并不属于一个具体的数据结构,它更多是一种数据结构的设计思想.大多NoSQL数据库核心思想都是基于L ...

  6. java中"=="和equals方法究竟有什么区别?

    为什么会说到这个问题呢,是因为在java中遇到这个问题太常见了,无论是在写代码时还是在面试时.下面就一起探讨一下它们之间的联系与区别吧. 首先对于这样的问题,一般是先单独把一个东西说清楚,然后再说另一 ...

  7. 2017icpc 西安 XOR

    XOR Consider an array AAA with n elements . Each of its element is A[i]A[i]A[i] (1≤i≤n)(1 \le i \le ...

  8. HDU-3790最短路径问题,第十遍终于过了~

    最短路径问题                                                                   Time Limit: 2000/1000 MS (J ...

  9. Jquery根据JSON生成Table

    先说下背景 本人属于juqery小白中的极品小白.基本对于JS jquery这些不懂.用到时候基本百度下 拿过来改改OK. 上面这东西让我弄了三天.可能对于其他人来说 一天就搞定了 .看来还真得去学一 ...

  10. Session&Cookie 的介绍和使用

    Session介绍与使用 1.Session基本介绍 Session:在计算机中,尤其是在网络应用中,称为“会话控制”.Session 对象存储特定用户会话所需的属性及配置信息.这样,当用户在应用程序 ...