[题目链接]

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. 洛谷 3871 [TJOI2010]中位数

    [题解] 平衡树模板题,不过因为可以离线,所以有别的做法.把询问倒着做,变成删掉数字.求中位数,于是可以二分+树状数组. #include<cstdio> #include<cstr ...

  2. BNUOJ 26223 CosmoCraft

    CosmoCraft Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: ...

  3. 添物不花钱学JavaEE(基础篇)- Servlet

    Servlet是Java Web开发必须要掌握的. Servlet是什么? A servlet is a Java technology based web component, managed by ...

  4. Codeforces Round #304 (Div. 2)-D. Soldier and Number Game,素因子打表,超时哭晕~~

    D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  5. MT6755 平台手机皮套驱动实现

    是自己写注册一个input device,模仿keypad,在对应的中断处理函数中上报power key的键值. 具体实现代码如下: 在 alps/kernel-3.10/drivers/misc/m ...

  6. android开发里跳过的坑——调用已安装视频播放器在有些机器上无效

    调用已安装视频播放器播放未修改之前的代码 private void startPlay(String fileName){ File file = new File(fileName); Intent ...

  7. [NOIP2004] 提高组 洛谷P1090 合并果子

    题目描述 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆. 每一次合并,多多可以把两堆果子合并到一起,消耗的体力等于两堆果子的重量之和.可 ...

  8. 【重要】MySQL常见面试题

    1. 主键 超键 候选键 外键 主 键: 数据库表中对储存数据对象予以唯一和完整标识的数据列或属性的组合.一个数据列只能有一个主键,且主键的取值不能缺失,即不能为空值(Null). 超 键: 在关系中 ...

  9. 2014ACM/ICPC亚洲区西安站现场赛 F color(二项式反演)

    题意:小球排成一排,从m种颜色中选取k种颜色给n个球上色,要求相邻的球的颜色不同,求可行的方案数,答案模1e9+7.T组数据,1<= n, m <= 1e9, 1 <= k < ...

  10. Ubuntu 16.04安装基于nethogs衍生的网络监控软件(应用实时网速监控)

    基于nethogs衍生的网络监控软件有如下所列举的: nettop显示数据包类型,按数据包的大小或数量排序. ettercap是以太网的网络嗅探器/拦截器/记录器 darkstat通过主机,协议等方式 ...